-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly handle <!-- <script </script in JavaScript
Fixes #1379
- Loading branch information
Showing
30 changed files
with
132 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
repository/Javascript-Core.package/JSStream.class/class/encodeLessThanIn.at.on..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
encoding - private | ||
encodeLessThanIn: aString at: anInteger on: aStream | ||
"Encode <, answer the number of characters coded" | ||
|
||
#('<!--' '<script' '</script') do: [ :each | | ||
(self hasString: aString subString: each at: anInteger) ifTrue: [ | ||
aStream nextPutAll: '\x3C'. | ||
aStream greaseNext: each size - 1 putAll: each startingAt: 2. | ||
^ each size ]. ]. | ||
aStream nextPut: $<. | ||
^ 1 |
10 changes: 10 additions & 0 deletions
10
...Javascript-Core.package/JSStream.class/class/encodeNonAsciiCharacter.withCodePoint.on..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
encoding - private | ||
encodeNonAsciiCharacter: aCharacter withCodePoint: anInteger on: aStream | ||
"U+2028 and U+2029 have to be treated as new lines" | ||
|
||
anInteger = 16r2028 "Line separator" | ||
ifTrue: [ aStream nextPutAll: '\u2028' ] | ||
ifFalse: [ | ||
anInteger = 16r2029 "Paragraph separator" | ||
ifTrue: [ aStream nextPutAll: '\u2029' ] | ||
ifFalse: [ aStream nextPut: aCharacter ] ] |
18 changes: 18 additions & 0 deletions
18
repository/Javascript-Core.package/JSStream.class/class/encodeString.fastOn..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
encoding - private | ||
encodeString: aString fastOn: aStream | ||
"Encode a String without <, much simpler implementation that can use #to:do" | ||
|
||
1 to: aString size do: [ :index | | ||
| char value encoded | | ||
char := aString at: index. | ||
value := char greaseInteger. | ||
value < JavascriptCharacters size | ||
ifFalse: [ | ||
self encodeNonAsciiCharacter: char withCodePoint: value on: aStream ] | ||
ifTrue: [ | ||
encoded := JavascriptCharacters at: value + 1. | ||
"we use nil markers becausee #isNil is faster than #isString because it's not | ||
actually sent" | ||
encoded isNil | ||
ifTrue: [ aStream nextPut: char ] | ||
ifFalse: [ aStream nextPutAll: encoded ] ] ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
repository/Javascript-Core.package/JSStream.class/class/encodeString.slowOn..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
encoding - private | ||
encodeString: aString slowOn: aStream | ||
"Strings with < a complicated encoding in Javascript" | ||
|
||
| index size | | ||
index := 1. | ||
size := aString size. | ||
[ index <= size ] whileTrue: [ | ||
| char value encoded | | ||
char := aString at: index. | ||
value := char greaseInteger. | ||
value < JavascriptCharacters size | ||
ifFalse: [ | ||
self encodeNonAsciiCharacter: char withCodePoint: value on: aStream. | ||
index := index + 1. ] | ||
ifTrue: [ | ||
encoded := JavascriptCharacters at: value + 1. | ||
"we use nil markers becausee #isNil is faster than #isString because it's not | ||
actually sent" | ||
encoded isNil | ||
ifTrue: [ | ||
"avoid that browsers mistakenly take the output as a closing tag" | ||
char = $< | ||
ifTrue: [ | ||
index := index + (self encodeLessThanIn: aString at: index on: aStream) ] | ||
ifFalse: [ | ||
aStream nextPut: char. | ||
index := index + 1. ] ] | ||
ifFalse: [ | ||
aStream nextPutAll: encoded. | ||
index := index + 1 ] ] ] |
10 changes: 10 additions & 0 deletions
10
repository/Javascript-Core.package/JSStream.class/class/hasString.subString.at..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
encoding - private | ||
hasString: aString subString: aSubstring at: anIntegerIndex | ||
"Strings with < a complicated encoding in Javascript" | ||
|
||
(anIntegerIndex + aSubstring size) > (aString size + 1) ifTrue: [ | ||
^ false ]. | ||
1 to: aSubstring size do: [ :index | | ||
(aString at: anIntegerIndex + index - 1) = (aSubstring at: index) | ||
ifFalse: [ ^ false ] ]. | ||
^ true |
3 changes: 1 addition & 2 deletions
3
repository/Javascript-Core.package/monticello.meta/categories.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
SystemOrganization addCategory: #'Javascript-Core'! | ||
SystemOrganization addCategory: 'Javascript-Core-Decorations'! | ||
self packageOrganizer ensurePackage: #'Javascript-Core' withTags: #('Decorations')! |
6 changes: 6 additions & 0 deletions
6
...ory/Javascript-Tests-Core.package/JSStreamTest.class/instance/testHasStringSubStringAt.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
tests-encoding | ||
testHasStringSubStringAt | ||
self assert: (JSStream hasString: 'Seaside' subString: 'Seaside' at: 1). | ||
self assert: (JSStream hasString: 'Seaside' subString: 'easide' at: 2). | ||
self deny: (JSStream hasString: 'Seaside' subString: 'Seaside' at: 2). | ||
self deny: (JSStream hasString: 'Seaside' subString: 'waytoolongtofix' at: 1). |
2 changes: 1 addition & 1 deletion
2
repository/Javascript-Tests-Core.package/monticello.meta/categories.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
SystemOrganization addCategory: #'Javascript-Tests-Core'! | ||
self packageOrganizer ensurePackage: #'Javascript-Tests-Core' withTags: #()! |
1 change: 0 additions & 1 deletion
1
repository/Javascript-Tests-Core.package/monticello.meta/version
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
repository/Prototype-Tests-Core.package/monticello.meta/version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 8 additions & 3 deletions
11
repository/Seaside-Canvas.package/WAScriptTag.class/instance/with..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
public | ||
with: aString | ||
with: aStringOrJSObject | ||
|
||
self attributes | ||
at: 'type' | ||
ifAbsentPut: [ 'text/javascript' ]. | ||
super with: [ | ||
aString ifNotNil: [ | ||
self document nextPutAll: aString greaseString ] ] | ||
aStringOrJSObject ifNotNil: [ | ||
aStringOrJSObject isJavascript | ||
ifTrue: [ | ||
self document stream javascript: aStringOrJSObject ] | ||
ifFalse: [ | ||
"we want to render a String directly and avoid escaping "" and '" | ||
self document nextPutAll: aStringOrJSObject greaseString ] ] ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...y/Seaside-Tests-Canvas.package/WADefaultScriptGeneratorTest.class/instance/testScripts.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
testing | ||
testScripts | ||
"https://html.spec.whatwg.org/#restrictions-for-contents-of-script-elements | ||
" | ||
self | ||
assert: [ :html | | ||
html | ||
script: (html logger log: '<!-- <script></script>'); | ||
paragraph: 'Test Paragraph' ] | ||
gives: '<html><head><title></title></head><body onload="onLoad()"><script type="text/javascript">console.log("\x3C!-- \x3Cscript>\x3C/script>")</script><p>Test Paragraph</p><script type="text/javascript">function onLoad(){};</script></body></html>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters