Skip to content

Commit

Permalink
Merge pull request #14073 from stevengj/crlf_literals
Browse files Browse the repository at this point in the history
normalize literal \r and \r\n chars in string literals to \n
  • Loading branch information
stevengj committed Nov 20, 2015
2 parents a419fda + fdec6bc commit e6cd2bc
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 @@ -1833,6 +1833,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 @@ -310,3 +310,7 @@ end
@test parse("a||b→c&&d") == Expr(:call, :,
Expr(symbol("||"), :a, :b),
Expr(symbol("&&"), :c, :d))

# 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 e6cd2bc

Please sign in to comment.