I agree.
It was nice to have a plan-B if it wasn't too much effort, but probably
should gut awk from the script for now since we know it to be broken on
even one system. We will always have it in history to re-evaluate in the
future if we have more trouble with sed and/or if someone figures out what
is wrong with the awk patterns listed.

Thanks for all your help.

Regards,
Jeff Adamson



From:   Johan Corveleyn <jcor...@gmail.com>
To:     Ant Developers List <dev@ant.apache.org>
Date:   11/03/2016 06:37 AM
Subject:        Re: ant wrapper script testing



On Mon, Oct 31, 2016 at 9:20 PM, Jeff Adamson <jwadam...@us.ibm.com> wrote:
>
> 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 }' )"

I'm afraid that doesn't work either:

[[
bash-4.1> diff ant.new ant.new.edited
63,66c63,66
<         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 }' )"
---
>         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 }' )"
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: build.xml does not exist!
Build failed
]]


I think it would indeed be better to focus on 'sed' only now, because
we can get it to work well cross-platform. No need to make it also
work with (n)awk.

--
Johan

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


Reply via email to