caddy icon indicating copy to clipboard operation
caddy copied to clipboard

fix quote within quotes formatted incorrectly by fmt

Open keystroke3 opened this issue 7 months ago • 3 comments

Fixes #6998 by looking for `" and "` patterns. If the first quote character is encountered before the second one, then the second character is treated as quoted and the outer quote block ends there. If the second character is encountered before the first, then the inner quote is considered closed, but the other one is not closed. So after the second " in `"" we are still in backtick block. For `"` we are not within any quote block after the last `

keystroke3 avatar Jun 02 '25 13:06 keystroke3

I think it could be easier to change quoted to not be a boolean but instead a rune and then check if it's 0 to mean not quoted. Then you just need two conditions very early in the loop if quoted == '"' && ch == '`' and vice versa to just eat the character as-is until the matching quote is found

francislavoie avatar Jun 02 '25 13:06 francislavoie

That's actually a great idea @francislavoie

mholt avatar Jun 06 '25 19:06 mholt

Sorry for the late reply. I will modify the code and update the pull request.

keystroke3 avatar Jun 11 '25 08:06 keystroke3

Oh this is going to be a nice addition! :)

moritzdietz avatar Aug 20 '25 06:08 moritzdietz

@keystroke3 any interest in finishing this up?

francislavoie avatar Oct 16 '25 05:10 francislavoie

Apologies for the delay in delivering the fix, life got in the way. I will attempt to work it and deliver by the end of next week. If I can't, then I will update the issue as such so someone else can pick it up.

keystroke3 avatar Oct 16 '25 09:10 keystroke3

I still want to fix this, I will need more time, hopefully this weekend I can make some time. Thanks for the patience.

keystroke3 avatar Oct 22 '25 11:10 keystroke3

I need to synchronize with the repo, so I will create a new pull request.

keystroke3 avatar Oct 25 '25 09:10 keystroke3

OK, I tried the suggested way of using a rune, but it proved more confusing for me to implement. So I used a string instead and checked the cases five we can have; no quote, backtick, quote, quoted backtick and backticked quote:

'', '`', '"', '"`', '`"'

If you feel the suggested way is better, please feel free to reject and re-write as you see fit. I would also like to see how the suggestion looks like. Thank you for your patience and the person who raised the issue as well.

keystroke3 avatar Oct 25 '25 15:10 keystroke3