Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

triple quotes lose escaped whitespace #21542

Closed
vtjnash opened this issue Apr 25, 2017 · 4 comments
Closed

triple quotes lose escaped whitespace #21542

vtjnash opened this issue Apr 25, 2017 · 4 comments
Labels
bug Indicates an unexpected problem or unintended behavior help wanted Indicates that a maintainer wants help on an issue or pull request minor change Marginal behavior change acceptable for a minor release strings "Strings!"

Comments

@vtjnash
Copy link
Member

vtjnash commented Apr 25, 2017

julia> s = """\n \t where is my newline?"""
"where is my newline?"
@ararslan ararslan added the strings "Strings!" label Apr 25, 2017
@KristofferC KristofferC added the bug Indicates an unexpected problem or unintended behavior label Dec 9, 2018
@StefanKarpinski StefanKarpinski added this to the 1.2 milestone Dec 10, 2018
@StefanKarpinski StefanKarpinski added the help wanted Indicates that a maintainer wants help on an issue or pull request label Dec 10, 2018
@jmkuhn
Copy link
Contributor

jmkuhn commented Feb 13, 2019

If the escaped newline is replaced by a literal newline, this is behaving as documented. The line of text is dedented and the newline immediately following the opening triple quote is stripped. What is the desired behavior here? Do we want escaped newlines to behave differently than literal newlines? Do we skip dedenting after an escaped newline? I like the current behavior of triple quotes including this example.

@alecloudenback
Copy link
Contributor

I would expect the behavior in this case to retain the whitespace. Here's the different way this string is treated under different ways of declaring it:

julia> s = """\n \t where is my newline?"""
"where is my newline?"

julia> print(s)
where is my newline?

julia> q = raw"\n \t where is my newline?"
"\\n \\t where is my newline?"

julia> q = "\n \t where is my newline?"
"\n \t where is my newline?"

julia> print(q)

         where is my newline?

If anything I think I would expect the single quotes to trim the whitespace, but the triple quote to retain it. Triple quote feels more literal to me. Especially sine the triple quote retains the non-literal spaces in the documentation:

julia> """    This
         is
           a test"""
"    This\nis\n  a test"

@StefanKarpinski
Copy link
Member

I think it would make sense to retain the escaped \n—the indent stripping logic is intended to allow text in """ in the middle of indented code to have a matching indent without having that indent end up in the resulting text block. That logic doesn't apply to the \n here. This would require changing the order in which string unescaping and unindenting occur: unindenting currently happens after unescaping, it should happen before.

@StefanKarpinski StefanKarpinski modified the milestones: 1.2, 1.x Mar 30, 2019
@StefanKarpinski StefanKarpinski added the minor change Marginal behavior change acceptable for a minor release label Mar 30, 2019
@vtjnash
Copy link
Member Author

vtjnash commented Mar 11, 2020

Fixed by #35001

@vtjnash vtjnash closed this as completed Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior help wanted Indicates that a maintainer wants help on an issue or pull request minor change Marginal behavior change acceptable for a minor release strings "Strings!"
Projects
None yet
Development

No branches or pull requests

6 participants