We will give this more thought. Ant only needs one replacement engine to
work on all platforms, but I don't know of a specific reason that nawk
should not be just as capable as sed.

To summarize,

Using 4-backslash replacement nawk on ubuntu:

arg       : -Dfoo=dollar$_backtick`_single'_double"_trailingbackslash\
quoted_arg: "-Dfoo=dollar\$_backtick\`_single'_double\"_trailingbackslash
\\"
....
     [echo] foo=dollar$_backtick`_single'_double"_trailingbackslash\_

Using 8-backslash replacement nawk on ubuntu:

arg       : -Dfoo=dollar$_backtick`_single'_double"_trailingbackslash\
quoted_arg: "-Dfoo=dollar\$_backtick\`_single'_double\"_trailingbackslash
\\\\"
....
     [echo] foo=dollar$_backtick`_single'_double"_trailingbackslash\\_

Using 4-backslash replacement nawk(?) on your machine:

arg       : -Dfoo=trail\ingbackslash\
quoted_arg: "-Dfoo=trail\ingbackslash\"
....
    error output (clearly failed to double the backslash during quoting)

Using 8-backslash replacement nawk on your machine:

arg       : -Dfoo=trail\ingbackslash\
quoted_arg: "-Dfoo=trail\\ingbackslash\\"
...
arg       : -Dfoo=trail\ingbackslash\
quoted_arg: "-Dfoo=trail\\ingbackslash\\"


The goal of the line is to replace one backslash literal with two. The
other awk patterns are correctly replacing with two backslashes in the
replacement pattern; introducing a single new backslash literal in the
output. Not sure why this backslash should be different. I think
4-backslash is the correct number unless something is doing an extra pass
of interpretation of the argument.


Maybe the slash-string pattern is being interpreted differently. Can we try
it as just plain double-quote strings?

      'awk')
        esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub("\\\\",
"\\\\"); print }' )"
        esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub("\\$",
"\\$");  print }' )"
        esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub("\"",
"\\\""); print }' )"
        esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub("`",
"\\`");  print }' )"

Regards,
Jeff Adamson



From:   Johan Corveleyn <jcor...@gmail.com>
To:     Ant Developers List <dev@ant.apache.org>
Date:   10/28/2016 07:36 PM
Subject:        Re: ant wrapper script testing



On Fri, Oct 28, 2016 at 10:41 PM, Johan Corveleyn <jcor...@gmail.com>
wrote:
...
> Yes, that works perfectly! On Solaris 11, with your latest version of
> the ant wrapper. When I run your test.sh, with the test.xml, I get
> exactly the correct output.
>
> However, with esc_tool=awk it fails. Don't know why yet, but the first
> property makes it fail already:
>
> [[
> bash-4.1> ./ant.new
> "-Dfoo=dollar\$_backtick\`_single'_double\"_trailingbackslash\\" -f
> test.xml
> Buildfile: build.xml does not exist!
> Build failed
> ]]
>
> With -version there is no problem, and running with '-f test.xml'
> without properties also works (and fwiw, "-Ddoublespace=  " also
> works).

Okay, so the problem with the awk variant on Solaris is only with the
trailing backslash. If I remove that from the test input, all other
tests work.

This change (doubling the backslashes even more) seems to fix it, but
I have no idea if it breaks the awk variant on other platforms:

[[
bash-4.1> diff ant.new ant.new.edited
63c63
<         esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{
gsub(/\\/, "\\\\"); print }' )"
---
>         esc_arg="$(printf '%s' "$esc_arg" | "$awk_exec" '{ gsub(/\\/,
"\\\\\\\\"); print }' )"
]]


Here is output of the awk variant with your version:

[[
bash-4.1> ./ant.new --execdebug "-Dfoo=trail\\ingbackslash\\" -f test.xml
arg       : -Dfoo=trail\ingbackslash\
quoted_arg: "-Dfoo=trail\ingbackslash\"
arg       : -f
quoted_arg: "-f"
arg       : test.xml
quoted_arg: "test.xml"
exec "$JAVACMD" -Xmx512m -Djava.awt.headless=true -XX:MaxPermSize=140m
-classpath "$LOCALCLASSPATH" -Dant.home="$ANT_HOME"
-Dant.library.dir="$ANT_LIB"  org.apache.tools.ant.launch.Launcher
-cp "$CLASSPATH"  "-Dfoo=trail\ingbackslash\" "-f" "test.xml"
Buildfile: build.xml does not exist!
Build failed
]]


And with ant.new.edited:

[[
bash-4.1> ./ant.new.edited --execdebug "-Dfoo=trail\\ingbackslash\\" -f
test.xml
arg       : -Dfoo=trail\ingbackslash\
quoted_arg: "-Dfoo=trail\\ingbackslash\\"
arg       : -f
quoted_arg: "-f"
arg       : test.xml
quoted_arg: "test.xml"
exec "$JAVACMD" -Xmx512m -Djava.awt.headless=true -XX:MaxPermSize=140m
-classpath "$LOCALCLASSPATH" -Dant.home="$ANT_HOME"
-Dant.library.dir="$ANT_LIB"  org.apache.tools.ant.launch.Launcher
-cp "$CLASSPATH"  "-Dfoo=trail\ingbackslash\" "-f" "test.xml"
Buildfile: /data/tools/ant/apache-ant-1.9.7/bin/test.xml

run:
     [echo] hello world
     [echo] foo=trail\ingbackslash\_
     [echo] bar=${bar}_
     [echo] nl=${nl}_
     [echo] nlnl=${nlnl}_
     [echo] nlnlnl=${nlnlnl}_
     [echo] doublespace=${doublespace}_
     [echo] end

BUILD SUCCESSFUL
Total time: 0 seconds
]]

--
Johan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@ant.apache.org
For additional commands, e-mail: dev-h...@ant.apache.org


Reply via email to