Skip to content

Commit

Permalink
Merge pull request #1368 from SeasideSt/1367-DictionaryasJson-does-no…
Browse files Browse the repository at this point in the history
…t-produce-valid-JSON-when-using-integer-keys

Fix #1367: keys of a JSON object should always be a string. + JSON tests cleanup
  • Loading branch information
Johan Brichau authored Jun 27, 2023
2 parents 2037d0c + 2f6e405 commit d0d3289
Show file tree
Hide file tree
Showing 71 changed files with 210 additions and 184 deletions.
5 changes: 3 additions & 2 deletions repository/BaselineOfSeaside3.package/.filetree
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"noMethodMetaData" : true,
"separateMethodMetaAndSource" : false,
"useCypressPropertiesFile" : true }
"noMethodMetaData" : true,
"useCypressPropertiesFile" : true
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ baselinejson: spec
package: 'Seaside-Tests-Pharo-JSON-Core' with: [
spec requires: #('Seaside-Tests-JSON') ] ].

spec for: #'pharo7.x' do: [
spec
package: 'Seaside-Pharo70-JSON-Extensions' with: [ spec requires: #('Seaside-JSON-Core') ];
package: 'Seaside-Pharo-JSON-Core' with: [ spec includes: #('Seaside-Pharo70-JSON-Extensions') ];
package: 'Seaside-Tests-Pharo70-JSON-Extensions'with: [ spec requires: #('Seaside-Tests-JSON') ];
package: 'Seaside-Tests-Pharo-JSON-Core' with: [ spec includes: #('Seaside-Tests-Pharo70-JSON-Extensions') ] ].

spec
for: #'gemstone'
do: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{
"category" : "BaselineOfSeaside3",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
],
"name" : "BaselineOfSeaside3",
"pools" : [
],
"super" : "BaselineOf",
"type" : "normal" }
"category" : "BaselineOfSeaside3",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [ ],
"name" : "BaselineOfSeaside3",
"type" : "normal"
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SystemOrganization addCategory: #'BaselineOfSeaside3'!
SystemOrganization addCategory: #BaselineOfSeaside3!
3 changes: 1 addition & 2 deletions repository/BaselineOfSeaside3.package/properties.json
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
{
}
{ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*seaside-gemstone-json-core
jsonKeyOn: aRenderer
self jsonOn: aRenderer
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*Seaside-JSON-Core
jsonKeyOn: aRenderer

self error: 'Only Strings can be used as keys in JSON objects.'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*seaside-json-core
jsonKeyOn: aRenderer
self jsonOn: aRenderer
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
double-disptach
double-dispatch
boolean: aBoolean
self document stream nextPutAll: (aBoolean ifTrue: [ 'true' ] ifFalse: [ 'false' ])
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
double-disptach
double-dispatch
dateAndTime: aDateAndTime
" Note: date and time is not standard json. So we use the ISO 8601 standard here. We convert to string to make it valid json "
self document stream nextPut: $".
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
double-disptach
double-dispatch
null
self document stream nextPutAll: 'null'
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
double-disptach
double-dispatch
number: aNumber
aNumber printOn: self document stream
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
double-disptach
double-dispatch
scaledDecimal: aScaledDecimal
| converter |
converter := GRSignPrinter new, (GRNumberPrinter new precision: aScaledDecimal scale).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
double-disptach
double-dispatch
string: aString
self document string: aString
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
stringKeysOnly: aBoolean
StringKeysOnly := aBoolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
stringKeysOnly
^ StringKeysOnly ifNil: [ false ]
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
private
openBrush
super openBrush.
key jsonOn: canvas.
self class stringKeysOnly
ifTrue: [ key jsonKeyOn: canvas ]
ifFalse: [ key jsonOn: canvas ].
self document stream nextPutAll: ': '
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"category" : "Seaside-JSON-Core-Brushes",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"classvars" : [
"StringKeysOnly"
],
"instvars" : [
"key"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*Seaside-Pharo70-JSON-Extensions
*Seaside-Pharo-JSON-Core
jsonOn: aRenderer
aRenderer object: [
self keysAndValuesDo: [ :key :value |
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SystemOrganization addCategory: #'Seaside-Pharo-JSON-Core'!
SystemOrganization addCategory: #'Seaside-Pharo-JSON-Core-Base'!
5 changes: 0 additions & 5 deletions repository/Seaside-Pharo70-JSON-Extensions.package/.filetree

This file was deleted.

This file was deleted.

Empty file.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ testBigArray
| result |
result := self parse: ' [ "a" , "b" ] '.
self assert: result isArray.
self assert: result size = 2.
self assert: result first = 'a'.
self assert: result second = 'b'
self assert: result size equals: 2.
self assert: result first equals: 'a'.
self assert: result second equals: 'b'
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ testBigObject
| result |
result := self parse: ' { "a" : 1 , "b" : 2 } '.
self assert: result isDictionary.
self assert: result size = 2.
self assert: (result at: 'a') = 1.
self assert: (result at: 'b') = 2
self assert: result size equals: 2.
self assert: (result at: 'a') equals: 1.
self assert: (result at: 'b') equals: 2
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ tests-real
testExplorerEvent
| result |
result := self parse: '{"recordset": null, "type": "change", "fromElement": null, "toElement": null, "altLeft": false, "keyCode": 0, "repeat": false, "reason": 0, "behaviorCookie": 0, "contentOverflow": false, "behaviorPart": 0, "dataTransfer": null, "ctrlKey": false, "shiftLeft": false, "dataFld": "", "qualifier": "", "wheelDelta": 0, "bookmarks": null, "button": 0, "srcFilter": null, "nextPage": "", "cancelBubble": false, "x": 89, "y": 502, "screenX": 231, "screenY": 1694, "srcUrn": "", "boundElements": {"length": 0}, "clientX": 89, "clientY": 502, "propertyName": "", "shiftKey": false, "ctrlLeft": false, "offsetX": 25, "offsetY": 2, "altKey": false}'.
self assert: (result at: 'type') = 'change'.
self assert: (result at: 'offsetY') = 2.
self assert: (result at: 'type') equals: 'change'.
self assert: (result at: 'offsetY') equals: 2.
self deny: (result at: 'altKey').
self assert: (result at: 'dataTransfer') isNil.
self assert: (result at: 'nextPage') = ''
self assert: (result at: 'nextPage') equals: ''
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ tests-real
testFirefoxEvent
| result |
result := self parse: '{"type": "change", "eventPhase": 2, "bubbles": true, "cancelable": true, "timeStamp": 0, "CAPTURING_PHASE": 1, "AT_TARGET": 2, "BUBBLING_PHASE": 3, "isTrusted": true, "MOUSEDOWN": 1, "MOUSEUP": 2, "MOUSEOVER": 4, "MOUSEOUT": 8, "MOUSEMOVE": 16, "MOUSEDRAG": 32, "CLICK": 64, "DBLCLICK": 128, "KEYDOWN": 256, "KEYUP": 512, "KEYPRESS": 1024, "DRAGDROP": 2048, "FOCUS": 4096, "BLUR": 8192, "SELECT": 16384, "CHANGE": 32768, "RESET": 65536, "SUBMIT": 131072, "SCROLL": 262144, "LOAD": 524288, "UNLOAD": 1048576, "XFER_DONE": 2097152, "ABORT": 4194304, "ERROR": 8388608, "LOCATE": 16777216, "MOVE": 33554432, "RESIZE": 67108864, "FORWARD": 134217728, "HELP": 268435456, "BACK": 536870912, "TEXT": 1073741824, "ALT_MASK": 1, "CONTROL_MASK": 2, "SHIFT_MASK": 4, "META_MASK": 8}'.
self assert: (result at: 'type') = 'change'.
self assert: (result at: 'eventPhase') = 2.
self assert: (result at: 'type') equals: 'change'.
self assert: (result at: 'eventPhase') equals: 2.
self assert: (result at: 'bubbles').
self assert: (result at: 'cancelable').
self assert: (result at: 'BACK') = 536870912
self assert: (result at: 'BACK') equals: 536870912
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ testInvalidObject
self assertInvalid: '{"a"}'.
self assertInvalid: '{"a":}'.
self assertInvalid: '{"a":"b",}'.
self assertInvalid: '{}}'
self assertInvalid: '{}}'.
self assertInvalid: '{1:"a"}'
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ testNestedArray
| result |
result := self parse: '[[2]]'.
self assert: result isArray.
self assert: result size = 1.
self assert: result size equals: 1.
result := result first.
self assert: result isArray.
self assert: result size = 1.
self assert: result first = 2
self assert: result size equals: 1.
self assert: result first equals: 2
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ testNestedObject
| result |
result := self parse: '{"object":{"1":"2"}} '.
self assert: result isDictionary.
self assert: result size = 1.
self assert: result size equals: 1.
result := result at: 'object'.
self assert: result isDictionary.
self assert: result size = 1.
self assert: (result at: '1') = '2'
self assert: result size equals: 1.
self assert: (result at: '1') equals: '2'
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ testNonBmpCodePoints
"dutch flag as two surrogate pairs"
parsed := self parse: '"\uD83C\uDDF3\uD83C\uDDF1"'.

self assert: parsed size = 2.
self assert: parsed first codePoint = 16r1F1F3. "Regional Indicator Symbol Letter N"
self assert: parsed second codePoint = 16r1F1F1 "Regional Indicator Symbol Letter L"
self assert: parsed size equals: 2.
self assert: parsed first codePoint equals: 16r1F1F3. "Regional Indicator Symbol Letter N"
self assert: parsed second codePoint equals: 16r1F1F1 "Regional Indicator Symbol Letter L"
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests-literals
testNumberFloat
self assert: (self parse: '0.0') = 0.0.
self assert: (self parse: '0.12') = 0.12.
self assert: (self parse: '-0.12') = -0.12.
self assert: (self parse: '12.34') = 12.34.
self assert: (self parse: '-12.34') = -12.34.
self assert: (self parse: '1.2e0') = 1.2.
self assert: (self parse: '1.2e+1') = 12.0.
self assert: (self parse: '1.2e-1') = 1.2e-1
self assert: (self parse: '0.0') equals: 0.0.
self assert: (self parse: '0.12') equals: 0.12.
self assert: (self parse: '-0.12') equals: -0.12.
self assert: (self parse: '12.34') equals: 12.34.
self assert: (self parse: '-12.34') equals: -12.34.
self assert: (self parse: '1.2e0') equals: 1.2.
self assert: (self parse: '1.2e+1') equals: 12.0.
self assert: (self parse: '1.2e-1') equals: 1.2e-1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tests-literals
testNumberInteger
self assert: (self parse: '0') = 0.
self assert: (self parse: '1') = 1.
self assert: (self parse: '-1') = -1.
self assert: (self parse: '12') = 12.
self assert: (self parse: '-12') = -12.
self assert: (self parse: '1e2') = 100.
self assert: (self parse: '1e+2') = 100
self assert: (self parse: '0') equals: 0.
self assert: (self parse: '1') equals: 1.
self assert: (self parse: '-1') equals: -1.
self assert: (self parse: '12') equals: 12.
self assert: (self parse: '-12') equals: -12.
self assert: (self parse: '1e2') equals: 100.
self assert: (self parse: '1e+2') equals: 100
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ tests-real
testSafariEvent
| result |
result := self parse: '{"returnValue": true, "timeStamp": 1226697417289, "eventPhase": 2, "type": "change", "cancelable": false, "bubbles": true, "cancelBubble": false, "MOUSEOUT": 8, "FOCUS": 4096, "CHANGE": 32768, "MOUSEMOVE": 16, "AT_TARGET": 2, "SELECT": 16384, "BLUR": 8192, "KEYUP": 512, "MOUSEDOWN": 1, "MOUSEDRAG": 32, "BUBBLING_PHASE": 3, "MOUSEUP": 2, "CAPTURING_PHASE": 1, "MOUSEOVER": 4, "CLICK": 64, "DBLCLICK": 128, "KEYDOWN": 256, "KEYPRESS": 1024, "DRAGDROP": 2048}'.
self assert: (result at: 'type') = 'change'.
self assert: (result at: 'eventPhase') = 2.
self assert: (result at: 'type') equals: 'change'.
self assert: (result at: 'eventPhase') equals: 2.
self assert: (result at: 'bubbles').
self deny: (result at: 'cancelBubble').
self deny: (result at: 'cancelable').
self assert: (result at: 'BLUR') = 8192
self assert: (result at: 'BLUR') equals: 8192
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ testSmallArray
| result |
result := self parse: '["a"]'.
self assert: result isArray.
self assert: result size = 1.
self assert: result first = 'a'
self assert: result size equals: 1.
self assert: result first equals: 'a'
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ testSmallObject
| result |
result := self parse: '{"a":1}'.
self assert: result isDictionary.
self assert: result size = 1.
self assert: (result at: 'a') = 1
self assert: result size equals: 1.
self assert: (result at: 'a') equals: 1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tests-literals
testString
self assert: (self parse: '""') = ''.
self assert: (self parse: '"foo"') = 'foo'.
self assert: (self parse: '"foo bar"') = 'foo bar'.
self assert: (self parse: '" foo "') = ' foo '
self assert: (self parse: '""') equals: ''.
self assert: (self parse: '"foo"') equals: 'foo'.
self assert: (self parse: '"foo bar"') equals: 'foo bar'.
self assert: (self parse: '" foo "') equals: ' foo '
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
tests-literals
testStringEscaped
self assert: (self parse: '"\""') = '"'.
self assert: (self parse: '"\\"') = '\'.
self assert: (self parse: '"\/"') = '/'.
self assert: (self parse: '"\b"') = (String with: Character backspace).
self assert: (self parse: '"\f"') = (String with: Character newPage).
self assert: (self parse: '"\n"') = (String with: Character lf).
self assert: (self parse: '"\r"') = (String with: Character cr).
self assert: (self parse: '"\t"') = (String with: Character tab).
self assert: (self parse: '"\u20Ac"') = (String with: (Character codePoint: 16r20AC))
self assert: (self parse: '"\""') equals: '"'.
self assert: (self parse: '"\\"') equals: '\'.
self assert: (self parse: '"\/"') equals: '/'.
self assert: (self parse: '"\b"') equals: (String with: Character backspace).
self assert: (self parse: '"\f"') equals: (String with: Character newPage).
self assert: (self parse: '"\n"') equals: (String with: Character lf).
self assert: (self parse: '"\r"') equals: (String with: Character cr).
self assert: (self parse: '"\t"') equals: (String with: Character tab).
self assert: (self parse: '"\u20Ac"') equals: (String with: (Character codePoint: 16r20AC))
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,17 @@ testObject
assert: [ :json |
json object: [
json key: '1' value: 1 ] ]
gives: '{"1": 1}'
gives: '{"1": 1}'.

WAJsonKeyValueBrush stringKeysOnly: true.
self
should: [
self
assert: [ :json |
json object: [
json key: 1 value: 1 ] ]
gives: '{"1": 1}' ]
raise: Error
withExceptionDo: [ :e | self assert: e messageText equals: 'Only Strings can be used as keys in JSON objects.' ].


Loading

0 comments on commit d0d3289

Please sign in to comment.