dart-lang / code_builder

A fluent API for generating valid Dart source code
https://pub.dev/packages/code_builder
BSD 3-Clause "New" or "Revised" License
423 stars 66 forks source link

`literalString` \r\n(CRLF) causes an error #452

Open medz opened 3 months ago

medz commented 3 months ago

In literalString, if the EOL is CRLF it will cause incorrect code to be generated. I checked the source code and found that literalString only handles the \n LF case, but did not notice the commonly used \r\n CRLF under Windows.

Example 1:

literalString('a\r\nb\r\nc');

Outout:

a
\nb
\nc

example 2:

literalString('a\nb\nc');

Outout:

a\nb\nc