Skip to content

Commit

Permalink
normalize literal \r and \r\n chars in string literals to \n (fixes #…
Browse files Browse the repository at this point in the history
…11988)

(cherry picked from commit fdec6bc)
ref #14073
  • Loading branch information
stevengj authored and tkelman committed Nov 29, 2015
1 parent 231dd4a commit 8d7683e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,14 @@
(list* ex (tostr custom b) e)
0)))

; convert literal \r and \r\n in strings to \n (issue #11988)
((eqv? c #\return) ; \r
(begin
(if (eqv? (peek-char p) #\linefeed) ; \r\n
(read-char p))
(write-char #\newline b)
(loop (read-char p) b e 0)))

(else
(write-char (not-eof-3 c) b)
(loop (read-char p) b e 0)))))
Expand Down
4 changes: 4 additions & 0 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,7 @@ let p = parse("try
@test p.args[2] === false
@test p.args[3].args[end] == parse("b,c = t")
end

# issue #11988 -- normalize \r and \r\n in literal strings to \n
@test "foo\nbar" == parse("\"\"\"\r\nfoo\r\nbar\"\"\"") == parse("\"\"\"\nfoo\nbar\"\"\"") == parse("\"\"\"\rfoo\rbar\"\"\"") == parse("\"foo\r\nbar\"") == parse("\"foo\rbar\"") == parse("\"foo\nbar\"")
@test '\r' == first("\r") == first("\r\n") # still allow explicit \r

0 comments on commit 8d7683e

Please sign in to comment.