Skip to content

Commit

Permalink
fix octal char parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
pfitzseb committed Jun 8, 2021
1 parent 550f0b6 commit c2cd117
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,14 @@ function valid_escaped_seq(s::AbstractString)
'A' <= nc <= 'F' ? n << 4 + (nc - 'A' + 10) : return false
end
return n <= 0x10ffff
elseif '0' <= c <= '7'
length(a) <= 3 || return false
n = c - '0'
while !isempty(a)
nc = popfirst!(a)
n = ('0' <= c <= '7') ? n << 3 + nc - '0' : return false
end
return n < 128
else
@static if VERSION < v"1.1.0"
c = string(c)
Expand Down
9 changes: 9 additions & 0 deletions test/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,9 @@ end""" |> test_expr
@test test_expr(raw"'\$'")
@test test_expr(raw"'\a'")
@test test_expr(raw"'\3'")
@test test_expr(raw"'\000'")
@test test_expr(raw"'\033'")
@test test_expr(raw"'\177'")
@test test_expr(raw"'\u222'")
@test test_expr(raw"'\ufff'")
@test test_expr(raw"'\x2'")
Expand All @@ -991,6 +994,12 @@ end""" |> test_expr
@test test_expr(raw"'\u2222'")
@test test_expr(raw"'\U2222'")
@test test_expr(raw"'\U22222'")

@test CSTParser.parse(raw"'\200'").head == :errortoken
@test CSTParser.parse(raw"'\300'").head == :errortoken
@test CSTParser.parse(raw"'\377'").head == :errortoken
@test CSTParser.parse(raw"'\600'").head == :errortoken
@test CSTParser.parse(raw"'\777'").head == :errortoken
@test CSTParser.parse(raw"'\x222'").head == :errortoken
@test CSTParser.parse(raw"'\u22222'").head == :errortoken
@test CSTParser.parse(raw"'\U222222'").head == :errortoken
Expand Down

0 comments on commit c2cd117

Please # to comment.