Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2009-02-02 20:49:55 +0000
committerThomas Watson2009-02-02 20:49:55 +0000
commit7e91bac89b6e44fc333a5c6873d8082257f9701c (patch)
treed5bb81c9efd2dde88b9f0cd433bfb9b62e833bdc /bundles/org.eclipse.osgi/console
parent9676ff5c32932ff5fab0aed6c239544dec2e36df (diff)
downloadrt.equinox.framework-7e91bac89b6e44fc333a5c6873d8082257f9701c.tar.gz
rt.equinox.framework-7e91bac89b6e44fc333a5c6873d8082257f9701c.tar.xz
rt.equinox.framework-7e91bac89b6e44fc333a5c6873d8082257f9701c.zip
Bug 262941 console chokes and dies with unclosed quotes
Diffstat (limited to 'bundles/org.eclipse.osgi/console')
-rw-r--r--bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandInterpreter.java45
1 files changed, 25 insertions, 20 deletions
diff --git a/bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandInterpreter.java b/bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandInterpreter.java
index b598093a6..ee23bcf49 100644
--- a/bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandInterpreter.java
+++ b/bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandInterpreter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2008 IBM Corporation and others.
+ * Copyright (c) 2003, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -78,28 +78,33 @@ public class FrameworkCommandInterpreter implements CommandInterpreter {
public String nextArgument() {
if (tok == null || !tok.hasMoreElements())
return null;
+ return consumeQuotes(tok.nextToken());
+ }
- String arg = tok.nextToken();
- if (arg.startsWith("\"")) { //$NON-NLS-1$
- if (arg.endsWith("\"")) { //$NON-NLS-1$
- if (arg.length() >= 2)
- // strip the beginning and ending quotes
- return arg.substring(1, arg.length() - 1);
- }
- String remainingArg = tok.nextToken("\""); //$NON-NLS-1$
- arg = arg.substring(1) + remainingArg;
- // skip to next whitespace separated token
- tok.nextToken(WS_DELIM);
- } else if (arg.startsWith("'")) { //$NON-NLS-1$ //$NON-NLS-2$
- if (arg.endsWith("'")) { //$NON-NLS-1$
- if (arg.length() >= 2)
- // strip the beginning and ending quotes
- return arg.substring(1, arg.length() - 1);
- }
- String remainingArg = tok.nextToken("'"); //$NON-NLS-1$
- arg = arg.substring(1) + remainingArg;
+ private String consumeQuotes(String arg) {
+ if (!(arg.startsWith("\"") || arg.startsWith("'"))) //$NON-NLS-1$//$NON-NLS-2$
+ return arg;
+ String quote = arg.substring(0, 1);
+ if (arg.endsWith(quote)) {
+ if (arg.length() >= 2)
+ // strip the beginning and ending quotes
+ return arg.substring(1, arg.length() - 1);
+ // single quote case; return empty string
+ return ""; //$NON-NLS-1$
+ }
+
+ try {
+ arg = arg.substring(1) + tok.nextToken(quote);
+ } catch (NoSuchElementException e) {
+ // should not happen
+ printStackTrace(e);
+ return ""; //$NON-NLS-1$
+ }
+ try {
// skip to next whitespace separated token
tok.nextToken(WS_DELIM);
+ } catch (NoSuchElementException e) {
+ // this is ok we are at the end
}
return arg;
}

Back to the top