[
https://issues.apache.org/jira/browse/CLI-262?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15867385#comment-15867385
]
Sashidharan commented on CLI-262:
---------------------------------
Hi Dustin,
Wrote one standalone java program and tested with " 'command \"suboption\"' "
The returned O/P was correct As i said
O/P is 'command "suboption"'
Code Sample used
public static void main(String[] args) {
//Test Util stripLeadingAndTrailingQuotes function
String str = "\"'one two'";
String str1 = "'command \"suboption\"' ";
System.out.println("O/P is
"+stripLeadingAndTrailingQuotes(str1));
}
static String stripLeadingAndTrailingQuotes(String str)
{
int length = str.length();
if (length > 1 && str.startsWith("\"") && str.endsWith("\"") &&
str.substring(1, length - 1).indexOf('"') == -1)
{
str = str.substring(1, length - 1);
}
return str;
}
Please have a look..
> Util.stripLeadingAndTrailingQuotes strips quotes that are unmatched
> -------------------------------------------------------------------
>
> Key: CLI-262
> URL: https://issues.apache.org/jira/browse/CLI-262
> Project: Commons CLI
> Issue Type: Bug
> Components: Parser
> Reporter: Dustin Cote
> Priority: Minor
>
> Util.stripLeadingAndTrailingQuotes is described as:
> {code}
> /**
> * Remove the leading and trailing quotes from <code>str</code>.
> * E.g. if str is '"one two"', then 'one two' is returned.
> *
> * @param str The string from which the leading and trailing quotes
> * should be removed.
> *
> * @return The string without the leading and trailing quotes.
> */
> {code}
> However, in cases where you have
> {code}
> "'one two'
> {code}
> the returned result is:
> {code}
> 'one two'
> {code}
> This leads to unexpected results. For example, an option like:
> {code}
> -option 'command "suboption"'
> {code}
> ends up being parsed as:
> {code}
> command "suboption
> {code}
> The method should be modified to only strip unmatched quotes or a new method
> should be made and added to the API.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)