Skip to content

Commit

Permalink
[feenkcom/gtoolkit#4072] Support strict symbol comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
akgrant43 committed Nov 6, 2024
1 parent 386a630 commit f1180e5
Show file tree
Hide file tree
Showing 36 changed files with 66 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing
knownEncodingIdentifiers
^ #( utf8lossy )
^ #( 'utf8lossy' )
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing
identifier
^ #utf8lossy
^ 'utf8lossy'
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing
knownEncodingIdentifiers
^ #( null )
^ #( 'null' )
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing
identifier
^ #null
^ 'null'
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing
knownEncodingIdentifiers
^ #( utf8 )
^ #( 'utf8' )
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
accessing
identifier
^ #utf8
^ 'utf8'
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ testing
testKnownEncodingIdentifiers
| all minimal asciiString notSelfIdentifying|
all := ZnCharacterEncoder knownEncodingIdentifiers asSet.
minimal := #(utf8 latin1 null ascii iso88591) asSet.
minimal := #('utf8' 'latin1' 'null' 'ascii' 'iso88591') asSet.
"make sure at least a minimal set is present"
self assert: (all intersection: minimal) equals: minimal.
asciiString := String withAll: ($a to: $z) , ($A to: $Z) , ($0 to: $9).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ handlePostRequest: request
(request hasEntity and: [ request contentType matches: ZnMimeType multiPartFormData ])
ifFalse: badRequest.
part := request entity
partNamed: #file
partNamed: 'file'
ifNone: badRequest.
newImage := part entity.
(newImage isNotNil and: [ newImage contentType matches: 'image/*' asZnMimeType ])
ifFalse: badRequest.
[ self formForImageEntity: newImage ] on: Error do: badRequest.
image := newImage.
^ ZnResponse redirect: #image
^ ZnResponse redirect: 'image'
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ public
handleRequest: request
"Dispatch between GET and POST on /image"

request uri path = #image
request uri path = 'image'
ifTrue: [
request method = #GET
ifTrue: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ testUpload
| image client |
image := self image.
client := ZnClient new.
client url: server localUrl; addPath: #image.
client addPart: (ZnMimePart fieldName: #file entity: image).
client url: server localUrl; addPath: 'image'.
client addPart: (ZnMimePart fieldName: 'file' entity: image).
client post.
self assert: client isSuccess.
client resetEntity; queryAt: #raw put: #true.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"commentStamp" : "SvenVanCaekenberghe 12/8/2019 14:05",
"commentStamp" : "",
"super" : "TestCase",
"category" : "Zinc-HTTP-Examples",
"classinstvars" : [ ],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
public
handleRequest: request
request uri firstPathSegment = #repl

request uri firstPathSegment = 'repl'
ifTrue: [
request method = #GET
ifTrue: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ handleRequest: znRequest
"try to resolve the uri path into a file for response. If not found dispatch the
request to the given delegate"
| response |
(znRequest method = 'GET')
(znRequest method = #GET)
ifTrue: [
response := (staticDelegate handleRequest: znRequest).
response isSuccess ifTrue: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ formTest2: request
| input page |
input := 'input'.
(request hasEntity and: [ request contentType matches: ZnMimeType applicationFormUrlEncoded ])
ifTrue: [ input := request entity at: #input ifAbsent: [ 'input' ] ].
ifTrue: [ input := request entity at: 'input' ifAbsent: [ 'input' ] ].
page := ZnHtmlOutputStream streamContents: [ :html |
html page: 'Form Test 2' do: [
html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ formTest3: request
contents := filename := contentType := ''.
(request hasEntity and: [ request contentType matches: ZnMimeType multiPartFormData ])
ifTrue: [
(request entity partNamed: #file ifNone: [ nil ])
(request entity partNamed: 'file' ifNone: [ nil ])
ifNotNil: [ :part |
filename := part fileName.
contents := part contents.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
accessing
method: string
method: aSymbol

method := ZnConstants knownHTTPMethods
detect: [ :each | each = string ]
ifNone: [ (ZnUnknownHttpMethod method: string) signal ]
detect: [ :each | each = aSymbol ]
ifNone: [ (ZnUnknownHttpMethod method: aSymbol) signal ]
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
accessing
method
<return: #Symbol>

^ method
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ readFrom: stream
| line lineStream |
line := (ZnLineReader on: stream) nextLine.
lineStream := line readStream.
self method: (lineStream upTo: Character space).
self method: (lineStream upTo: Character space) asSymbol.
self uri: (lineStream upTo: Character space).
self version: (lineStream upToEnd)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ parseHttpDate: string
| tokens day month year hour minute second months map yearToken |
tokens := (string findTokens: #( $ $- $: $, )) allButFirst.
tokens last = 'GMT' ifTrue: [ tokens := tokens allButLast ].
months := #(jan feb mar apr may jun jul aug sep oct nov dec).
months := #('jan' 'feb' 'mar' 'apr' 'may' 'jun' 'jul' 'aug' 'sep' 'oct' 'nov' 'dec').
(Integer readFrom: tokens first ifFail: [ 0 ]) isZero
ifTrue: [ map := #(2 1 6 3 4 5) ]
ifFalse: [ map := #(1 2 3 4 5 6) ].
Expand Down
9 changes: 8 additions & 1 deletion repository/Zinc-HTTP.package/monticello.meta/categories.st
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
self packageOrganizer ensurePackage: #'Zinc-HTTP' withTags: #(#'Client-Server' #Core #Exceptions #Logging #Streaming #Support #Variables)!
SystemOrganization addCategory: #'Zinc-HTTP'!
SystemOrganization addCategory: #'Zinc-HTTP-Client-Server'!
SystemOrganization addCategory: #'Zinc-HTTP-Core'!
SystemOrganization addCategory: #'Zinc-HTTP-Exceptions'!
SystemOrganization addCategory: #'Zinc-HTTP-Logging'!
SystemOrganization addCategory: #'Zinc-HTTP-Streaming'!
SystemOrganization addCategory: #'Zinc-HTTP-Support'!
SystemOrganization addCategory: #'Zinc-HTTP-Variables'!
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ testCreate
returned as a JSON string and as the Location header"

| data objectUri |
data := Dictionary with: #x -> 'foo' with: #y -> 'bar'.
data := Dictionary with: 'x' -> 'foo' with: 'y' -> 'bar'.
client
addPathSegment: 'objects';
contents: data;
Expand All @@ -25,4 +25,4 @@ testCreate
self assert: client isSuccess.
data keysAndValuesDo: [ :key :value |
(client contents at: key) = value ].
self assert: (client contents at: #'object-uri') equals: objectUri
self assert: (client contents at: 'object-uri') equals: objectUri
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ testQuery
"Any query parameters are seen as a conjunctive filter.
Here we execute a GET /storage/object?string=five to find a entry where
the key 'string' equals 'five'. Note that the uri is returned."

| data objectUri |

client addPathSegment: 'objects'.
1 to: 10 do: [ :each |
data := Dictionary with: #int -> each with: #string -> each asWords.
data := Dictionary with: 'int' -> each with: 'string' -> each asWords.
client
contents: data;
post.
self assert: client isCreated ].
client resetEntity.
client
queryAt: #string put: 'five';
queryAt: 'string' put: 'five';
get.
self assert: client isSuccess.
objectUri := client contents first.
client
url: objectUri;
get.
self assert: client isSuccess.
self assert: (client contents at: #int) equals: 5
self assert: (client contents at: 'int') equals: 5
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ testUpdate
"To update an existing object you PUT a new JSON map representation to an existing uri"

| data objectUri |
data := Dictionary with: #x -> 'foo' with: #y -> 'bar'.
data := Dictionary with: 'x' -> 'foo' with: 'y' -> 'bar'.
client
addPathSegment: 'objects';
contents: data;
post.
self assert: client isCreated.
objectUri := client response location.
client resetEntity.
data at: #z put: 100.
data at: 'z' put: 100.
client
url: objectUri;
contents: data;
Expand All @@ -22,5 +22,5 @@ testUpdate
self assert: client isSuccess.
data keysAndValuesDo: [ :key :value |
(client contents at: key) = value ].
self assert: (client contents at: #'object-uri') equals: objectUri.
self assert: (client contents at: #z) equals: 100
self assert: (client contents at: 'object-uri') equals: objectUri.
self assert: (client contents at: 'z') equals: 100
4 changes: 2 additions & 2 deletions repository/Zinc-REST.package/monticello.meta/categories.st
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SystemOrganization addCategory: #'Zinc-REST'!
SystemOrganization addCategory: 'Zinc-REST-Server'!
SystemOrganization addCategory: 'Zinc-REST-Tests'!
SystemOrganization addCategory: #'Zinc-REST-Server'!
SystemOrganization addCategory: #'Zinc-REST-Tests'!
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
private
isSchemeNotUsingDoubleSlash: schemeString
^ self class schemesNotUsingDoubleSlash , self class schemesOptionallyNotUsingDoubleSlash
includes: schemeString asLowercase
includes: schemeString asLowercase asSymbol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ testQueryAccessing
| url |
url := 'http://www.google.com/?one=1&two=2' asZnUrl.
self assert: url hasQuery.
self assert: url queryKeys sorted equals: #(one two).
self assert: url queryKeys sorted equals: #('one' 'two').
self assert: (url queryAt: 'two' ifAbsent: [ self fail ]) equals: '2'.
self assert: (url queryAt: 'three' ifAbsent: [ #missing ]) equals: #missing.
url queryAt: 'one' ifPresent: [ :value | self assert: value equals: '1' ].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ testQueryManipulation
url := 'http://www.google.com/?one=1&two=2' asZnUrl.
url queryAt: 'three' put: '3'.
url queryRemoveKey: 'one'.
self assert: url queryKeys sorted equals: #(three two).
self assert: url queryKeys sorted equals: #('three' 'two').
self assert: (url queryAt: 'two') equals: '2'.
self assert: (url queryAt: 'three') equals: '3'.
url queryRemoveAll.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ testGetGeoIP
ifFail: [ ^ self fail ];
get.
self assert: result isDictionary.
self assert: (result at: #country) equals: 'BE'.
self assert: (result at: 'country') equals: 'BE'.
client close
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ testOptions
request method = #OPTIONS
ifTrue: [ | response |
response := ZnResponse noContent.
response headers at: #Allow put: 'GET, HEAD'.
response headers at: 'Allow' put: 'GET, HEAD'.
response ]
ifFalse: [ ZnResponse badRequest: request ] ].
(client := ZnClient new)
options: server localUrl.
self assert: client isSuccess.
self deny: client response hasEntity.
self assert: (client response headers at: #Allow) equals: 'GET, HEAD'.
self assert: (client response headers at: 'Allow') equals: 'GET, HEAD'.
client close ]
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ testPatch
request method = #PATCH
ifTrue: [| response |
response := ZnResponse noContent.
response headers at: #Etag put: '"e0023aa4f"'.
response headers at: 'Etag' put: '"e0023aa4f"'.
response]
ifFalse: [ ZnResponse badRequest: request ] ].
(client := ZnClient new)
patch: server localUrl contents: 'Some data as text'.
self assert: client isSuccess.
self deny: client response hasEntity.
self assert: (client response headers at: #Etag) equals: '"e0023aa4f"'.
self assert: (client response headers at: 'Etag') equals: '"e0023aa4f"'.
client close ]
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ testReadingMultiline
self assert: (headers includesKey: 'Content-Length').
self assert: (headers at: 'Content-Type') equals: 'text/plain'.
self assert: (headers at: 'Content-Length') equals: '128'.
self assert: (headers includesKey: #Long).
self assert: (headers at: #long) equals: 'foo bar baz'
self assert: (headers includesKey: 'Long').
self assert: (headers at: 'long') equals: 'foo bar baz'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
testing
testWriting
| requestLine string |
requestLine := ZnRequestLine method: 'GET' uri: '/foo/bar/xyz.txt'.
requestLine := ZnRequestLine method: #GET uri: '/foo/bar/xyz.txt'.
string := String streamContents: [ :stream | requestLine writeOn: stream ].
self assert: string equals: 'GET /foo/bar/xyz.txt HTTP/1.1' , String crlf
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ testMergedFields
request := ZnRequest post: 'http://host.com/foo?x=1&y=2&x=3'.
form := ZnApplicationFormUrlEncodedEntity new.
form
at: #z put: '100';
at: #z add: '200';
at: #y put: '0'.
at: 'z' put: '100';
at: 'z' add: '200';
at: 'y' put: '0'.
request entity: form.
mergedFields := request mergedFields.
self assert: mergedFields keys sorted equals: #(x y z).
self assert: (mergedFields at: #x) sorted equals: #('1' '3').
self assert: (mergedFields at: #y) sorted equals: #('0' '2').
self assert: (mergedFields at: #z) sorted equals: #('100' '200')
self assert: mergedFields keys sorted equals: #('x' 'y' 'z').
self assert: (mergedFields at: 'x') sorted equals: #('1' '3').
self assert: (mergedFields at: 'y') sorted equals: #('0' '2').
self assert: (mergedFields at: 'z') sorted equals: #('100' '200')
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ testFormTest2
addPathSegment: 'form-test-2'.
inputs do: [ :each |
client
formAt: #input put: each;
formAt: 'input' put: each;
post.
self assert: client isSuccess.
self assert: (client contents includesSubstring: each) ] ]
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ testLogging
client get: (server localUrl addPathSegment: #error).
self deny: client isSuccess.
server delegate
map: #redirect
map: 'redirect'
to: [ :request | ZnResponse redirect: #welcome ].
client get: (server localUrl addPathSegment: #redirect).
self assert: client isSuccess.
Expand Down

0 comments on commit f1180e5

Please sign in to comment.