Skip to content

Unintuitive whitespace stripping in indented string after escaped newline #16011

Description

@jiamingc

Describe the bug

If I have an escaped newline (''\n) in a indented string, any whitespace after the escaped newline will be stripped that whitespace were part of the leading indentation of a line. This feels unintuitive to me, since I expect the indentation stripping to only be relevant for code formatting.

Steps To Reproduce

evaluate

''
  ''\n asdf
''

result:

"\nasdf\n"

Expected behavior

I expect the space after the escaped newline to be preserved:

"\n asdf\n"

Metadata

nix-env (Nix) 2.34.7

Additional context

Having no leading indentation leads to no whitespace stripping after the newline, for example

''
''\n asdf
''

evaluates to

"\n asdf\n"

as expected.

There's precedence for not fixing these types of bugs for backwards compatibility, but maybe there could be a note added to the manual? https://nix.dev/manual/nix/2.24/language/syntax#string-literal

Checklist


Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    buglanguageThe Nix expression language; parser, interpreter, primops, evaluation, etc

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions