JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.59k stars 5.48k forks source link

Inconsistent line ending from `@raw_str` in Windows #38908

Open korsbo opened 3 years ago

korsbo commented 3 years ago

A raw-string is normally parsed to have Linux-style line endings, \n, even on Windows. Great! However, you get Windows-style line endings, \r\n, if the linebreak in the raw-string is preceded by a backslash.

julia> raw"foo\bar
baz"
"foo\\bar\nbaz"   # linux line-ending, \n

julia> raw"foo\
bar
baz"
"foo\\\r\nbar\nbaz"   # windows style line-ending, \r\n, followed by linux style.
julia> versioninfo()
Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
musm commented 3 years ago

I can't reproduce this

julia> versioninfo()
Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, icelake-client)
Environment:
  JULIA_EDITOR = code.cmd
  JULIA_NUM_THREADS = 8

julia> raw"foo\bar
       baz"
"foo\\bar\nbaz"

julia>  raw"foo\
       bar
       baz"
"foo\\\nbar\nbaz"
StefanKarpinski commented 3 years ago

May depend on what kind of line endings your editor saves the file with. Might be possible to reproduce by printing and parsing directly in Julia. I also suspect it doesn't only happen on Windows, that's just the only platform where editors produce \r line endings.

StefanKarpinski commented 3 years ago

Yup:

julia> eval(Meta.parse("""raw"foo\\\rbar\rbaz\""""))
"foo\\\rbar\nbaz"