The specification of Julia for reading text files and the different behavior between operating systems

What is the specification of Julia for reading text files which have newlines (e.g. "\n", "\r\n", "\r")? My program has a bug related to the different behavior between operating systems about newlines.

I made a following file lf.txt on macOS by:

write("lf.txt", "---\nhello:\n...\n")

then added and committed and pushed by Git. On Windows, I pulled it by Git and read it by:

str = read("lf.txt", String)

but got

julia> @show str
str = "---\r\nhello:\r\n...\r\n"

Why? Does Git something wrong?

This is git behavior, not related to julia. Julia just reads whatever is on disk.

3 Likes

I fixed EOL newlines for some files by adding

*.yaml text eol=lf
*.crlf.yaml text eol=crlf

to .gitattributes.

2 Likes