File tree Expand file tree Collapse file tree
java/org/apache/commons/cli
test/org/apache/commons/cli Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,14 +62,12 @@ else if (str.startsWith("-"))
6262 */
6363 static String stripLeadingAndTrailingQuotes (String str )
6464 {
65- if (str .startsWith ("\" " ))
65+ int length = str .length ();
66+ if (length > 1 && str .startsWith ("\" " ) && str .endsWith ("\" " ) && str .substring (1 , length - 1 ).indexOf ('"' ) == -1 )
6667 {
67- str = str .substring (1 , str .length ());
68- }
69- if (str .endsWith ("\" " ))
70- {
71- str = str .substring (0 , str .length () - 1 );
68+ str = str .substring (1 , length - 1 );
7269 }
70+
7371 return str ;
7472 }
7573}
Original file line number Diff line number Diff line change @@ -35,5 +35,9 @@ public void testStripLeadingHyphens()
3535 public void testStripLeadingAndTrailingQuotes ()
3636 {
3737 assertEquals ("foo" , Util .stripLeadingAndTrailingQuotes ("\" foo\" " ));
38+ assertEquals ("foo \" bar\" " , Util .stripLeadingAndTrailingQuotes ("foo \" bar\" " ));
39+ assertEquals ("\" foo\" bar" , Util .stripLeadingAndTrailingQuotes ("\" foo\" bar" ));
40+ assertEquals ("\" foo\" and \" bar\" " , Util .stripLeadingAndTrailingQuotes ("\" foo\" and \" bar\" " ));
41+ assertEquals ("\" " , Util .stripLeadingAndTrailingQuotes ("\" " ));
3842 }
3943}
You can’t perform that action at this time.
0 commit comments