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

fix #35305, need escaping when printing string macro calls #35309

Merged
merged 2 commits into from
Mar 31, 2020

Conversation

JeffBezanson
Copy link
Member

fix #35305

@JeffBezanson JeffBezanson added backport 1.4 bugfix This change fixes an existing bug display and printing Aesthetics and correctness of printed representations of objects. labels Mar 30, 2020
Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this actually fixes it, because of #29580, but it is better.

@JeffBezanson
Copy link
Member Author

It looks like that is about printing Regex and SubstitutionString; this is for expressions:

julia> :(r"\\\\")
:(r"\\\\")

But I should change this to only escape backslashes and quotes I think.

@vtjnash
Copy link
Member

vtjnash commented Mar 30, 2020

True, but those happen to be raw"" strings also, like these.

Also, some part of that fix is included in https://github.com/JuliaLang/julia/pull/34111/files#diff-85598a9f3fb3fcced8c43d0472c30888R545

@JeffBezanson
Copy link
Member Author

Oh, nice, we should add that code and use it here.

mgkuhn and others added 2 commits March 30, 2020 17:34
Implementation of the raw-string escaping convention. Can also be
used to escape command-line arguments for Windows C/C++/Julia
applications, which use the same \" escaping convention as
Julia non-standard string literals.
@JeffBezanson
Copy link
Member Author

Added the commit from #34111. I edited it a bit to not print surrounding "s, since escape_string doesn't.

@JeffBezanson JeffBezanson merged commit 351d7e9 into master Mar 31, 2020
@JeffBezanson JeffBezanson deleted the jb/fix35305 branch March 31, 2020 14:58
@KristofferC KristofferC mentioned this pull request Apr 4, 2020
27 tasks
@mgkuhn
Copy link
Contributor

mgkuhn commented Apr 10, 2020

@JeffBezanson The reason I printed the surrounding " in my original version of escape_raw_string was that I really couldn't think of any reason not to: the entire function really only makes sense if its output is immediately followed by a ", because of the way this encoding specially treats trailing backslashes at the end of the string (expecting the recipient to see that followed by a "). This is different from how escape_string() works, where not only the delimiter is configurable, but also nothing special happens at the end of the string. I'd therefore stay with my original version, as the analogy to escape_string() is not so clear cut.
(The difference in mathematical terms: escape_string() is an isomorphism over string concatenation, whereas escape_string_raw() isn't, because of the case of strings ending in a backslash.)

@JeffBezanson
Copy link
Member Author

That makes sense, but it's easy to add the quotes if you want them, and impossible to remove them if you don't (however unlikely that might be).

write(io, '\\')
escapes -= 1
end
escapes = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this line is unecessary since escape is decremented to 0 by L559

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug display and printing Aesthetics and correctness of printed representations of objects.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

String representation of expressions with quotes in non-standard string literals
5 participants