Skip to content

Commit

Permalink
image should not contain file separator.
Browse files Browse the repository at this point in the history
Fixes #522
  • Loading branch information
demarey committed Feb 21, 2022
1 parent 03a2605 commit 629b856
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/PharoLauncher-Core/PhLImage.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ PhLImage class >> isSubclassForLocation: imageFileReference [
^ versionFile exists and: [ versionFile contents beginsWith: self versionPrefix ]
]

{ #category : #validating }
PhLImage class >> isValidName: anImageName [
^ anImageName isNotEmpty and: [ (anImageName includesAny: #/\) not ]
]

{ #category : #'instance creation' }
PhLImage class >> location: imageFileReference [
| instance |
Expand Down
23 changes: 17 additions & 6 deletions src/PharoLauncher-Spec2/PhLImageCreationPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Class {
#classTraits : 'TPhLInteractionTrait classTrait',
#instVars : [
'reservedImagesNamesCache',
'isNameOk',
'imageName',
'createButton',
'initScriptText',
'initScript',
'editInitScriptButton',
'descriptionText',
'imageNameCheck'
'imageNameCheck',
'isNameValid'
],
#category : #'PharoLauncher-Spec2'
}
Expand Down Expand Up @@ -66,12 +66,13 @@ PhLImageCreationPresenter >> checkNewName: name [
I use a variable to know the state during the last validation."

| isValid |
isValid := name isEmpty or: [ reservedImagesNamesCache ifNotNil: [ reservedImagesNamesCache includes: name asLowercase ] ].
isValid := (PhLImage isValidName: name)
and: [ reservedImagesNamesCache ifNotNil: [ (reservedImagesNamesCache includes: name asLowercase) not ] ].

"Image already in the right state. We skip."
isNameOk = isValid ifTrue: [ ^ self ].
isNameValid = isValid ifTrue: [ ^ self ].

(isNameOk := isValid) ifTrue: [ self showNameError ] ifFalse: [ self showNameOk ]
(isNameValid := isValid ) ifTrue: [ self showNameOk ] ifFalse: [ self showNameError ]
]

{ #category : #closing }
Expand Down Expand Up @@ -175,6 +176,11 @@ PhLImageCreationPresenter >> initializePresenters [
createButton disable
]

{ #category : #testing }
PhLImageCreationPresenter >> isNameValid [
^ isNameValid
]

{ #category : #initialization }
PhLImageCreationPresenter >> modelChanged [

Expand All @@ -190,6 +196,11 @@ PhLImageCreationPresenter >> noInitializationScriptItem [
^ (FileSystem memory root / 'No initialization script') ensureCreateFile
]

{ #category : #accessing }
PhLImageCreationPresenter >> okIcon [
^ self application iconNamed: #smallOk
]

{ #category : #action }
PhLImageCreationPresenter >> openScriptPresenter [

Expand Down Expand Up @@ -220,7 +231,7 @@ PhLImageCreationPresenter >> showNameOk [

self ifValidTemplate: [ createButton enable ].
imageNameCheck
image: (self application iconNamed: #smallOk);
image: self okIcon;
help: 'Image name is valid!'
]

Expand Down
1 change: 1 addition & 0 deletions src/PharoLauncher-Spec2/PharoLauncherApplication.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ PharoLauncherApplication >> scriptsDirectory: aFileReference [

{ #category : #ui }
PharoLauncherApplication >> shouldUpdateTemplateSources [

^ self newConfirm
title: 'Update';
label: 'Update available for Pharo Launcher templates sources!';
Expand Down
15 changes: 15 additions & 0 deletions src/PharoLauncher-Tests-Core/PhLImageTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ PhLImageTest >> testDescriptionIsSetWhenNoDescriptionInMetadataButDescriptionFil
equals: desc.
]

{ #category : #tests }
PhLImageTest >> testImageNameIsNotValidWhenContainingFileSeparator [

self deny: (PhLImage isValidName: 'fo/o').
self deny: (PhLImage isValidName: '123\4').
]

{ #category : #tests }
PhLImageTest >> testImageNameIsValidWithLettersAndNumbers [

self assert: (PhLImage isValidName: 'foo').
self assert: (PhLImage isValidName: '1234').
self assert: (PhLImage isValidName: 'Fo23')
]

{ #category : #tests }
PhLImageTest >> testPhLImageSerialization [
| stonString |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ PhLImageCreationPresenterTest >> setUp [
yourself)
]

{ #category : #tests }
PhLImageCreationPresenterTest >> testImageNameIsNotValidWhenContainingFileSeparator [

presenter checkNewName: 'foo/'.

self deny: presenter isNameValid.
]

{ #category : #tests }
PhLImageCreationPresenterTest >> testImageNameIsValid [

presenter checkNewName: 'nonExistingImageName'.

self assert: presenter isNameValid.
]

{ #category : #tests }
PhLImageCreationPresenterTest >> testInitializationScriptListUpdatedWhenScriptPresenterDoChange [
| scriptPresenter |
Expand Down

0 comments on commit 629b856

Please sign in to comment.