Passing arguments containing double-quote or backslash characters results in errors in ant shell script. Examples: $ ant '-Dx="' /home/jwa/.sdkman/candidates/ant/current/bin/ant: 1: eval: Syntax error: Unterminated quoted string $ ant "-Dx=\\" /home/jwa/.sdkman/candidates/ant/current/bin/ant: 1: eval: Syntax error: Unterminated quoted string
Thanks for the patch.
As per the WHATSNEW file I see that the modifications for this issue change the interpretation/evaluation of quotes within an ant argument. I have an issue with 1.9.7. Previously with ant 1.9.6 and earlier the line expanded to -Dbr.cmd="co-r ", which is correct. Now after updating to Ant 1.9.7 the expansion is messed up. It actually evaluates to '-Dbr.cmd="co'-r ' " ' including all of the quotes shown. It’s hard to read so I added spaces around the one double quote at the end. It actually looks like ‘”’. Then ant gives the error -r option invalid, because as you can see the -r is abandoned between the literal single quotes. Needless to say, that I can modify the scripts we use, so the field itself does not contain the double quotes, and that the field is only surrounded by them. But I was surprised that my build failed almost immediately as ant was kicked off.
What is the pertinent arguments and what is the output of execdebug when you run it? e.g. apache-ant-1.9.7$ ./bin/ant --execdebug -Dbr.cmd="co-r " -version exec "$JAVACMD" -Xmx512m -classpath "$LOCALCLASSPATH" -Dant.home="$ANT_HOME" -Dant.library.dir="$ANT_LIB" org.apache.tools.ant.launch.Launcher -cp "$CLASSPATH" "-Dbr.cmd=co-r " "-version" Apache Ant(TM) version 1.9.7 compiled on April 9 2016
(In reply to jwadamson from comment #3) > What is the pertinent arguments and what is the output of execdebug when you > run it? e.g. > > apache-ant-1.9.7$ ./bin/ant --execdebug -Dbr.cmd="co-r " -version > exec "$JAVACMD" -Xmx512m -classpath "$LOCALCLASSPATH" -Dant.home="$ANT_HOME" > -Dant.library.dir="$ANT_LIB" org.apache.tools.ant.launch.Launcher -cp > "$CLASSPATH" "-Dbr.cmd=co-r " "-version" > Apache Ant(TM) version 1.9.7 compiled on April 9 2016 I tried to first see how the line gets interpreted and then run the above commands as you suggested. here is the output: # with 1.9.6 you get $ ant --execdebug '-Dbranch.command="co' -r '"' -version exec "/home/build/softwares/jdk/jre/bin/java" -classpath "/home/build/softwares/ant/lib/ant-launcher.jar" -Dant.home="/home/build/softwares/ant" -Dant.library.dir="/home/build/softwares/ant/lib" org.apache.tools.ant.launch.Launcher -cp "/home/build/softwares/ant/lib/ant.jar:/u04/tomcat/common/lib/servlet.jar" "-Dbranch.command="co" "-r" """ "-version" Apache Ant(TM) version 1.9.6 compiled on June 29 2015 #with 1.9.7 you get $ ant --execdebug '-Dbranch.command="co' -r '"' -version exec "$JAVACMD" -classpath "$LOCALCLASSPATH" -Dant.home="$ANT_HOME" -Dant.library.dir="$ANT_LIB" org.apache.tools.ant.launch.Launcher -cp "$CLASSPATH" "-Dbranch.command=\"co" "-r" "\"" "-version" Unknown argument: -r As I've also said, I have no issue reworking the script so the quotes are not part of the value. That is strange to me anyway. there is no need to have it that way.
Thank you for the example. I think the 1.9.6 behavior in your case was objectively incorrect. It worked out to the right answer, but for the wrong reasons. '-Dbranch.command="co' -r '"' In /bin/sh, quoting does not nest. So the example command line has 3 separate arguments passed to ant: `-Dbranch.commmand="co` `-r` `"` (a literal double-quote) The ant script in 1.9.6 was smushing these back together as (quoting the space between each original argument) `"-Dbranch.command="co" "-r" """`. /bin/sh processing then interprets this mess as a single argument in the exec command (with some spurious empty strings concatenated into the value): `-Dbranch.command=co -r ` The ant script in 1.9.7 keeps those original 3 arguments separate and causes the error about the `-r` argument.
(In reply to jwadamson from comment #5) > Thank you for the example. I think the 1.9.6 behavior in your case was > objectively incorrect. It worked out to the right answer, but for the wrong > reasons. > > '-Dbranch.command="co' -r '"' > > In /bin/sh, quoting does not nest. So the example command line has 3 > separate arguments passed to ant: > `-Dbranch.commmand="co` > `-r` > `"` (a literal double-quote) > > The ant script in 1.9.6 was smushing these back together as (quoting the > space between each original argument) > `"-Dbranch.command="co" "-r" """`. > /bin/sh processing then interprets this mess as a single argument in the > exec command (with some spurious empty strings concatenated into the value): > `-Dbranch.command=co -r ` > > The ant script in 1.9.7 keeps those original 3 arguments separate and causes > the error about the `-r` argument. I agree. Once I looked at the evaluated value, I was actually surprised it worked. I've reworked the scripts to pass it the correct way. Only the value, and no double quotes. works fine in both versions of ant.