Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Removed '\1' (and other) invalid escape sequences from chars. Fixes #…
  • Loading branch information
asterite committed Apr 18, 2017
1 parent 8ad21bc commit c49cf61
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions spec/compiler/lexer/lexer_spec.cr
Expand Up @@ -456,6 +456,8 @@ describe "Lexer" do
assert_syntax_error "'\\u{110000}'", "invalid unicode codepoint (too large)"
assert_syntax_error ":+1", "unexpected token"

assert_syntax_error "'\\1'", "invalid char escape sequence"

it_lexes_string %("\\1"), String.new(Bytes[1])
it_lexes_string %("\\4"), String.new(Bytes[4])
it_lexes_string %("\\10"), String.new(Bytes[8])
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/crystal/syntax/lexer.cr
Expand Up @@ -587,6 +587,10 @@ module Crystal
case char1 = next_char
when '\\'
case char2 = next_char
when '\\'
@token.value = '\\'
when '\''
@token.value = '\''
when 'b'
@token.value = '\b'
when 'e'
Expand All @@ -609,7 +613,7 @@ module Crystal
when '\0'
raise "unterminated char literal", line, column
else
@token.value = char2
raise "invalid char escape sequence", line, column
end
when '\''
raise "invalid empty char literal (did you mean '\\\''?)", line, column
Expand Down

0 comments on commit c49cf61

Please sign in to comment.