Skip to content

Commit

Permalink
fix #24558, use same rules for char and string escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Nov 20, 2017
1 parent ed9f8e5 commit e6938b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2179,25 +2179,18 @@
(begin (read-char (ts:port s)) firstch)
(let ((b (open-output-string)))
(let loop ((c firstch))
(if (eqv? c #\')
#t
(begin (if (eqv? c #\")
(error "invalid character literal") ;; issue 14683
#t)
(if (not (eqv? c #\'))
(begin (if (eqv? c #\") ;; issue 14683
(error "invalid character literal"))
(write-char (not-eof-1 c) b)
(if (eqv? c #\\)
(write-char
(not-eof-1 (read-char (ts:port s))) b))
(loop (read-char (ts:port s))))))
(let ((str (unescape-string (io.tostring! b))))
(if (= (length str) 1)
;; one byte, e.g. '\xff'. maybe not valid UTF-8, but we
;; want to use the raw value as a codepoint in this case.
(wchar (aref str 0))
(if (or (not (= (string-length str) 1))
(not (string.isutf8 str)))
(error "invalid character literal")
(string.char str 0))))))))
(write-char (not-eof-1 (read-char (ts:port s)))
b))
(loop (read-char (ts:port s))))))
(let ((str (tostr #f b)))
(if (= (string-length str) 1)
(string.char str 0)
(error "invalid character literal")))))))

;; symbol/expression quote
((eq? t ':)
Expand Down
6 changes: 6 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ end
@test_throws ParseError Meta.parse("'\\A\"'")
@test Meta.parse("'\"'") == Meta.parse("'\\\"'") == '"' == "\""[1] == '\42'

# issue #24558
@test_throws ParseError Meta.parse("'\\xff'")
@test_throws ParseError Meta.parse("'\\x80'")
@test_throws ParseError Meta.parse("'ab'")
@test '\u2200' == "\u2200"[1]

@test_throws ParseError Meta.parse("f(2x for x=1:10, y")

# issue #15223
Expand Down

0 comments on commit e6938b5

Please sign in to comment.