yq icon indicating copy to clipboard operation
yq copied to clipboard

Fixes #1692 - Inconsistent backslash escaping in literal strings

Open KrisShannon opened this issue 1 year ago • 2 comments

This is the simplest fix I can come up with for #1692

Before:

% yq -nr eval '"\\"'
\\

After:

% yq -nr eval '"\\"'
\

It does change behaviour. Anyone who is currently using double backslashes in their literal strings will need to change them to quadruple backslashes.

It also makes it possible to use a literal string of a windows path for a filename that starts with n:

% yq -nr eval '"C:\\tmp\\nigel.xlsx"'
C:\tmp\nigel.xlsx

KrisShannon avatar Oct 05 '23 07:10 KrisShannon

It may make sense to extract the creation of the string Replacer outside of the stringValue function and use a single Replacer for all literals instead of a new one each time. I'm not a golang programmer so I don't know what the best way to do that would be.

KrisShannon avatar Oct 05 '23 07:10 KrisShannon

Can you add some tests for this :)

mikefarah avatar Oct 10 '23 03:10 mikefarah

Closing this till unit tests are added

mikefarah avatar Mar 04 '24 04:03 mikefarah