Thank you for reporting a bug for me, in the first place. No, fix is not good (I notified the author). Similar test fails:

>perl -MShellQuote::Any::Tiny=shell_quote -E "system $^X, '-E', 'say f +or @ARGV', 1, shell_quote(qq(\x5c\x5c \x5c)), 2" 1 \\\ \ 2

According to comment in source, [we now] "escape backslash that is followed by a backslash, or the last backslash". That's not what rules 4-7 in MS guidelines say, if we 'reverse' them. 'Reverse', because they say how to parse a command line, and, of course, Perl does it OK for all test cases provided on that page:

perl -E "system $^X, '-E', 'say for @ARGV', qq(\x22abc\x22 d e)" perl -E "system $^X, '-E', 'say for @ARGV', qq(a\x5c\x5c\x5cb d\x22e f +\x22g h)" perl -E "system $^X, '-E', 'say for @ARGV', qq(a\x5c\x5c\x5c\x22b c d) +" perl -E "system $^X, '-E', 'say for @ARGV', qq(a\x5c\x5c\x5c\x5c\x22b +c\x22 d e)"

While we need the opposite: to escape arguments, so that when Perl #1 simply glues them together, another program (e.g. Perl #2) breaks the CL to the same arguments. Line 24

$arg =~ s/(\\(?!.*\\)|\\(?=\\)|")/\\$1/g;

could be replaced with

$arg =~ s/\\(?=\\*(?:"|$))/\\\\/g; $arg =~ s/"/\\"/g;

Then round-trip tests pass OK (though they are trivial, of course):

perl -MShellQuote::Any::Tiny=shell_quote -E "system $^X, '-E', 'say fo +r @ARGV', map {shell_quote $_} qw(abc d e)" perl -MShellQuote::Any::Tiny=shell_quote -E "system $^X, '-E', 'say fo +r @ARGV', map {shell_quote $_} qq(a\x5c\x5c\x5cb), 'de fg', 'h'" perl -MShellQuote::Any::Tiny=shell_quote -E "system $^X, '-E', 'say fo +r @ARGV', map {shell_quote $_} qq(a\x5c\x22b), 'c', 'd'" perl -MShellQuote::Any::Tiny=shell_quote -E "system $^X, '-E', 'say fo +r @ARGV', map {shell_quote $_} qq(a\x5c\x5cb c), 'd', 'e'"

Edit. P.S. Issue fixed (on the same day) in 0.007 version. I'm out of issues.

:-)


In reply to Re^4: Having to manually escape quote character in args to "system"? by vr
in thread Having to manually escape quote character in args to "system"? by vr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.