diff --git a/lib/coffee-script/lexer.js b/lib/coffee-script/lexer.js index e5fb6f40..f4b16700 100644 --- a/lib/coffee-script/lexer.js +++ b/lib/coffee-script/lexer.js @@ -168,7 +168,7 @@ default: return 0; } - if (octalEsc = /^(?:\\.|[^\\])*\\[0-7]/.test(string)) { + if (octalEsc = /^(?:\\.|[^\\])*\\(?:0[0-7]|[1-7])/.test(string)) { this.error("octal escape sequences " + string + " are not allowed"); } this.line += count(string, '\n'); diff --git a/src/lexer.coffee b/src/lexer.coffee index 54651803..23d68b1b 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -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 diff --git a/test/strict.coffee b/test/strict.coffee index a098ced7..55ff4535 100644 --- a/test/strict.coffee +++ b/test/strict.coffee @@ -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", -> @@ -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", ->