You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2015/06/07 11:32:00 UTC
[jira] [Comment Edited] (GROOVY-7352) CliBuilder kills head/tail
quotes from argument
[ https://issues.apache.org/jira/browse/GROOVY-7352?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14576164#comment-14576164 ]
Paul King edited comment on GROOVY-7352 at 6/7/15 9:31 AM:
-----------------------------------------------------------
The {{CliBuilder}} class on Groovy's master branch has been changed to use {{DefaultParser}} from Commons CLI 1.3,
I ran the following test script which eliminates any shell distortions:
{code}
def cli = new CliBuilder()
cli.with {
f longOpt:'json-filter','jq expression', args: 1
}
def vals = ['test', 't"es"t',
"'test", "test'", "'test'",
'"test', 'test"', '"test"']
vals.each {
def opt = cli.parse(['-f', it])
assert opt.f == it
}
{code}
It fails but only on the very last entry: "test". This is improved but still a little weird.
So, the leading and trailing quote cases are now fixed or are caused by the groovy shell script not CliBuilder.
was (Author: paulk):
Groovy's master branch has been changed to use {{DefaultParser}} from Commons CLI 1.3,
I ran the following test script which eliminates any shell distortions:
{code}
def cli = new CliBuilder()
cli.with {
f longOpt:'json-filter','jq expression', args: 1
}
def vals = ['test', 't"es"t',
"'test", "test'", "'test'",
'"test', 'test"', '"test"']
vals.each {
def opt = cli.parse(['-f', it])
assert opt.f == it
}
{code}
It fails but only on the very last entry: "test". This is improved but still a little weird.
So, the leading and trailing quote cases are now fixed or are caused by the groovy shell script not CliBuilder.
> CliBuilder kills head/tail quotes from argument
> -----------------------------------------------
>
> Key: GROOVY-7352
> URL: https://issues.apache.org/jira/browse/GROOVY-7352
> Project: Groovy
> Issue Type: Bug
> Components: command line processing
> Affects Versions: 2.4.0
> Environment: $ groovy -v
> Groovy Version: 2.4.0 JVM: 1.8.0_31 Vendor: Oracle Corporation OS: Linux
> apostrophes works as expected:
> $ groovy bug-paf-2.groovy -f "'test'"
> 'test'
> $ groovy bug-paf-2.groovy -f "'test"
> 'test
> $ groovy bug-paf-2.groovy -f "test'"
> test'
> (problem is only with quotes inside argument value)
> I wanted to pass json filter expression -f ".Field == \"\""
> and got last quote killed.
> Reporter: Alexander Petrossian (PAF)
>
> {code}
> $ cat bug-paf-2.groovy
> def cli = new CliBuilder()
> cli.with {
> f longOpt:'json-filter','jq expression', args: 1
> }
> def opt = cli.parse(args)
> print "${opt.f}\n"
> $
> {code}
> {noformat}
> $ groovy bug-paf-2.groovy -f '"test"' #expected "test", got:
> test
> $ groovy bug-paf-2.groovy -f '"test' #expected "test, got:
> test
> $ groovy bug-paf-2.groovy -f 'test"' #expected test", got:
> test
> {noformat}
> {noformat}
> $ groovy bug-paf-2.groovy -f "\"test\"" #expected "test", got:
> test
> $ groovy bug-paf-2.groovy -f "\"test" #expected "test, got:
> test
> $ groovy bug-paf-2.groovy -f "test\"" #expected test", got:
> test
> {noformat}
> looks like somebody clears head/tail quotes.
> this must not be done.
> removing quotes/apostrophes is a task for shell, once data gets to argv, no unquoting must be done on it.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)