-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Incorrect escaping in Printf on master (@sprintf("GAP[%%]")) #37784
Comments
There is also a newly added unit test that fails in Julia 1.5.2, see (pull/37470). @test @sprintf("%s%%%s", "a", "b") == "a%%b" I propose to update it to @test @sprintf("%s%%%s", "a", "b") == "a%b" |
Fixes #37784. The classic blunder of not unescaping the escaped when printing. I considered trying to detect escaped chars during format construction-time, but there isn't a clean way to utilize the current `Printf.Format` structure to achieve this, since it requires `length(f.formats) == length(f.substringranges) + 1`, and `f.substringranges` must be the concretely typed `Vector{UnitRange{Int}}`. Doing the unescaping in `Printf.format` when we're outputting seems to not incur any performance penalty and seems like a pretty clean fix since all outputting is handled in this one function anyway.
Fixes #37784. The classic blunder of not unescaping the escaped when printing. I considered trying to detect escaped chars during format construction-time, but there isn't a clean way to utilize the current `Printf.Format` structure to achieve this, since it requires `length(f.formats) == length(f.substringranges) + 1`, and `f.substringranges` must be the concretely typed `Vector{UnitRange{Int}}`. Doing the unescaping in `Printf.format` when we're outputting seems to not incur any performance penalty and seems like a pretty clean fix since all outputting is handled in this one function anyway.
Wow! Thanks for the rapid response. You solved the existing test case, but the original issue with The printing in function Thus, I propose to add to more tests like: @test Printf.@sprintf("1%%") == "1%"
@test Printf.@sprintf("%%1") == "%1"
@test Printf.@sprintf("1%%2") == "1%2"
@test Printf.@sprintf("1%%%d", 2) == "1%2"
@test Printf.@sprintf("1%%2%%3") == "1%2%3" |
I have tried to fix that in my fork petvana/julia/tree/jq/37784. I have moved the format detection into a separate inlined function for better readability. If you like it, I can submit a pull request to the branch. It succeeds in all tests, but I have concerns about its performance. @quinnj Which instances you use for performance testing? |
Make sure to run any performance testing on top of #37802. At least for floats. |
@petvana, yes, feel free to do a PR against my branch and I can review/try it out. |
On master, the Printf library is redisegned but the escape sequences seems not to be hanled correctly (or like in C as written in docs). Now, it is not possible to print single '%' in the middle of string.
C style
The problem of the new design comes from the commit #32859 where the structure in
stdlib/Printf/src/Printf.jl
expects that
length(substringranges) == length(formats) + 1
but it is not true in general if"%%"
occurs in the middle of the string format. To provide simple example, there is no format but several substrings in the following:Utilized version of master branch
Btw, all it works well on 1.5.2.
The text was updated successfully, but these errors were encountered: