Skip to content

Commit

Permalink
corrections for octal escape sequences; allows "\0" alone; see jashke…
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra committed Apr 20, 2012
1 parent eabcb2c commit 46ff770
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/coffee-script/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ exports.Lexer = class Lexer
@token 'STRING', @escapeLines string
else
return 0
if octalEsc = /^(?:\\.|[^\\])*\\[0-7]/.test string
if octalEsc = /^(?:\\.|[^\\])*\\(?:0[0-7]|[1-7])/.test string
@error "octal escape sequences #{string} are not allowed"
@line += count string, '\n'
string.length
Expand Down
33 changes: 21 additions & 12 deletions test/strict.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

# helper to assert that code complies with strict prohibitions
strict = (code, msg) ->
throws (-> CoffeeScript.compile code), null, msg
throws (-> CoffeeScript.compile code), null, msg ? code
strictOk = (code, msg) ->
doesNotThrow (-> CoffeeScript.compile code), msg
doesNotThrow (-> CoffeeScript.compile code), msg ? code


test "octal integer literals prohibited", ->
Expand All @@ -32,19 +32,28 @@ test "octal integer literals prohibited", ->
strictOk '`01`'

test "octal escape sequences prohibited", ->
strict '"\\0"'
strict '"\\1"'
strict '"\\7"'
strict '"\\000"'
strict '"\\001"'
strict '"\\777"'
strict '"_\\0"'
strict '"\\0_"'
strict '"_\\0_"'
strict '"\\08"'
strict '"\\\\\\0"'
strict '"_\\1"'
strict '"\\1_"'
strict '"_\\1_"'
strict '"\\\\\\1"'
strictOk '"\\0"'
eq "\x00", "\0"
strictOk '"\\08"'
eq "\x008", "\08"
strictOk '"\\0\\8"'
eq "\x008", "\0\8"
strictOk '"\\8"'
strictOk '"\\\\0"'
strictOk '"\\\\\\\\0"'
strictOk "`'\\0'`"
eq "8", "\8"
strictOk '"\\\\1"'
eq "\\" + "1", "\\1"
strictOk '"\\\\\\\\1"'
eq "\\\\" + "1", "\\\\1"
strictOk "`'\\1'`"
eq "\\" + "1", `"\\1"`


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

0 comments on commit 46ff770

Please sign in to comment.