Skip to content

Commit c49cf61

Browse files
author
Ary Borenszweig
committed
Removed '\1' (and other) invalid escape sequences from chars. Fixes #4309
1 parent 8ad21bc commit c49cf61

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

spec/compiler/lexer/lexer_spec.cr

+2
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ describe "Lexer" do
456456
assert_syntax_error "'\\u{110000}'", "invalid unicode codepoint (too large)"
457457
assert_syntax_error ":+1", "unexpected token"
458458

459+
assert_syntax_error "'\\1'", "invalid char escape sequence"
460+
459461
it_lexes_string %("\\1"), String.new(Bytes[1])
460462
it_lexes_string %("\\4"), String.new(Bytes[4])
461463
it_lexes_string %("\\10"), String.new(Bytes[8])

src/compiler/crystal/syntax/lexer.cr

+5-1
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,10 @@ module Crystal
587587
case char1 = next_char
588588
when '\\'
589589
case char2 = next_char
590+
when '\\'
591+
@token.value = '\\'
592+
when '\''
593+
@token.value = '\''
590594
when 'b'
591595
@token.value = '\b'
592596
when 'e'
@@ -609,7 +613,7 @@ module Crystal
609613
when '\0'
610614
raise "unterminated char literal", line, column
611615
else
612-
@token.value = char2
616+
raise "invalid char escape sequence", line, column
613617
end
614618
when '\''
615619
raise "invalid empty char literal (did you mean '\\\''?)", line, column

0 commit comments

Comments
 (0)