Skip to content

Commit e6cd2bc

Browse files
committed
Merge pull request #14073 from stevengj/crlf_literals
normalize literal \r and \r\n chars in string literals to \n
2 parents a419fda + fdec6bc commit e6cd2bc

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/julia-parser.scm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,14 @@
18331833
(list* ex (tostr custom b) e)
18341834
0)))
18351835

1836+
; convert literal \r and \r\n in strings to \n (issue #11988)
1837+
((eqv? c #\return) ; \r
1838+
(begin
1839+
(if (eqv? (peek-char p) #\linefeed) ; \r\n
1840+
(read-char p))
1841+
(write-char #\newline b)
1842+
(loop (read-char p) b e 0)))
1843+
18361844
(else
18371845
(write-char (not-eof-3 c) b)
18381846
(loop (read-char p) b e 0)))))

test/parse.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,7 @@ end
310310
@test parse("a||b→c&&d") == Expr(:call, :,
311311
Expr(symbol("||"), :a, :b),
312312
Expr(symbol("&&"), :c, :d))
313+
314+
# issue #11988 -- normalize \r and \r\n in literal strings to \n
315+
@test "foo\nbar" == parse("\"\"\"\r\nfoo\r\nbar\"\"\"") == parse("\"\"\"\nfoo\nbar\"\"\"") == parse("\"\"\"\rfoo\rbar\"\"\"") == parse("\"foo\r\nbar\"") == parse("\"foo\rbar\"") == parse("\"foo\nbar\"")
316+
@test '\r' == first("\r") == first("\r\n") # still allow explicit \r

0 commit comments

Comments
 (0)