Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B28B3200C1C for ; Wed, 15 Feb 2017 08:33:48 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B136E160B70; Wed, 15 Feb 2017 07:33:48 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 08157160B46 for ; Wed, 15 Feb 2017 08:33:47 +0100 (CET) Received: (qmail 62216 invoked by uid 500); 15 Feb 2017 07:33:47 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 62204 invoked by uid 99); 15 Feb 2017 07:33:46 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Feb 2017 07:33:46 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 602C91A5F0E for ; Wed, 15 Feb 2017 07:33:46 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.199 X-Spam-Level: X-Spam-Status: No, score=-1.199 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id lcyQtxYs607v for ; Wed, 15 Feb 2017 07:33:45 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 3ADC85FD84 for ; Wed, 15 Feb 2017 07:33:45 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id A02F0E06B9 for ; Wed, 15 Feb 2017 07:33:42 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id D88C924134 for ; Wed, 15 Feb 2017 07:33:41 +0000 (UTC) Date: Wed, 15 Feb 2017 07:33:41 +0000 (UTC) From: "Sashidharan (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (CLI-262) Util.stripLeadingAndTrailingQuotes strips quotes that are unmatched MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 15 Feb 2017 07:33:48 -0000 [ 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 str. > * 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)