On 10/15/2023 9:24 AM, Garret Wilson wrote:
On 10/15/2023 1:31 AM, Alexander Kriegisch wrote:
Let us settle on only using double quotes to enclose arguments containing spaces. Then, we do not need to escape single quotes and can use them literally. But we do need to escape nested double quotes.
Just for a moment, forget about Bash/PowerShell/CMD escaping rules. What are escaping the rules of the Maven Exec Plugin? What does it consider a delimiter for indicating multiple arguments?

I guess at this point it's easier just to dig into the source code. The relevant plugin source code seems to be here (after a cursory glance):

https://github.com/mojohaus/exec-maven-plugin/blob/ddefecff84ebbf6427a6bb9eb6c2fdb332bfac7c/src/main/java/org/codehaus/mojo/exec/ExecMojo.java#L600

It appears to be using `CommandLineUtils.translateCommandline( argsProp )` to parse the string input into an array. A little more searching seems to indicate that that utility is here:

https://github.com/codehaus-plexus/plexus-utils/blob/d4f0d2de40c5d6cb5d80c8a199fa4f32a4e59879/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java#L348C85-L348C85

That code uses `StringTokenizer` constructed using `new StringTokenizer(toProcess, "\"\' ", true)`. So yes, Alexander, it does indeed appear to be using both single quotes and and double quotes as delimiters.

So next is the question of escaping. The [documentation](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/StringTokenizer.html) for `StringTokenizer` says nothing about escaping. I glanced (extremely quickly) over the source code for `StringTokenizer`, and I don't see it translating any escape sequences.

Thus if escaping is happening, it would have to be in `CommandLineUtils.translateCommandline( argsProp )`. And it would be possible, as it uses the `StringTokenizer` option to return delimiters. But glancing (again very quickly) over the `CommandLineUtils` code, I don't see any escaping handling at all.

Thus my conclusion is that the Maven Exec Plugin handles either single quotes or double quotes as the delimiter, but /does not handle escaping in either case/. You pick one or the other, and cross your fingers that the given argument does not contain that delimiter, because there's no way to escape it ahead of time.

All the discussion of escaping at the Bash/PowerShell/CMD level, while useful in its own context, has absolutely zero bearing on the issue I was raising, which was: how to escape a quote at the Maven Exec Plugin level. The answer seems to be: you can't.

(I glanced over the source code extremely fast, so I could have missed something. If so please point it out to me!)

Garret

Reply via email to