Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 46ff770

Browse files
corrections for octal escape sequences; allows "\0" alone; see jashkenas#1547
Relevant sections of the spec: * http://es5.github.com/#C * http://es5.github.com/#B.1.2 * http://es5.github.com/#x7.8.4
1 parent eabcb2c commit 46ff770

3 files changed

Lines changed: 23 additions & 14 deletions

File tree

lib/coffee-script/lexer.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lexer.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ exports.Lexer = class Lexer
164164
@token 'STRING', @escapeLines string
165165
else
166166
return 0
167-
if octalEsc = /^(?:\\.|[^\\])*\\[0-7]/.test string
167+
if octalEsc = /^(?:\\.|[^\\])*\\(?:0[0-7]|[1-7])/.test string
168168
@error "octal escape sequences #{string} are not allowed"
169169
@line += count string, '\n'
170170
string.length

test/strict.coffee

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
# helper to assert that code complies with strict prohibitions
2020
strict = (code, msg) ->
21-
throws (-> CoffeeScript.compile code), null, msg
21+
throws (-> CoffeeScript.compile code), null, msg ? code
2222
strictOk = (code, msg) ->
23-
doesNotThrow (-> CoffeeScript.compile code), msg
23+
doesNotThrow (-> CoffeeScript.compile code), msg ? code
2424

2525

2626
test "octal integer literals prohibited", ->
@@ -32,19 +32,28 @@ test "octal integer literals prohibited", ->
3232
strictOk '`01`'
3333

3434
test "octal escape sequences prohibited", ->
35-
strict '"\\0"'
35+
strict '"\\1"'
3636
strict '"\\7"'
37-
strict '"\\000"'
37+
strict '"\\001"'
3838
strict '"\\777"'
39-
strict '"_\\0"'
40-
strict '"\\0_"'
41-
strict '"_\\0_"'
42-
strict '"\\08"'
43-
strict '"\\\\\\0"'
39+
strict '"_\\1"'
40+
strict '"\\1_"'
41+
strict '"_\\1_"'
42+
strict '"\\\\\\1"'
43+
strictOk '"\\0"'
44+
eq "\x00", "\0"
45+
strictOk '"\\08"'
46+
eq "\x008", "\08"
47+
strictOk '"\\0\\8"'
48+
eq "\x008", "\0\8"
4449
strictOk '"\\8"'
45-
strictOk '"\\\\0"'
46-
strictOk '"\\\\\\\\0"'
47-
strictOk "`'\\0'`"
50+
eq "8", "\8"
51+
strictOk '"\\\\1"'
52+
eq "\\" + "1", "\\1"
53+
strictOk '"\\\\\\\\1"'
54+
eq "\\\\" + "1", "\\\\1"
55+
strictOk "`'\\1'`"
56+
eq "\\" + "1", `"\\1"`
4857

4958

5059
test "duplicate property definitions in object literals are prohibited", ->

0 commit comments

Comments
 (0)