From c425e51911827e9182f651ff9df1cc9ba671f936 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Wed, 22 Aug 2012 14:13:31 +0200 Subject: [PATCH] Added support for nested quotes in arguments when calling external commands from Cooja --- .../java/se/sics/cooja/dialogs/CompileContiki.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/dialogs/CompileContiki.java b/tools/cooja/java/se/sics/cooja/dialogs/CompileContiki.java index 9978d7702..fda1b8699 100644 --- a/tools/cooja/java/se/sics/cooja/dialogs/CompileContiki.java +++ b/tools/cooja/java/se/sics/cooja/dialogs/CompileContiki.java @@ -43,7 +43,6 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Reader; import java.util.ArrayList; -import java.util.Arrays; import java.util.regex.Pattern; import java.util.regex.Matcher; @@ -89,11 +88,15 @@ public class CompileContiki { final MessageList compilationOutput, boolean synchronous) throws Exception { - Pattern p = Pattern.compile("([^\\s\"']|\"[^\"]*\"|'[^']*')+"); + Pattern p = Pattern.compile("([^\\s\"']+|\"[^\"]*\"|'[^']*')"); Matcher m = p.matcher(command); ArrayList commandList = new ArrayList(); - while(m.find()) { - commandList.add(m.group().replaceAll("['\"]","")); + while(m.find()) { + String arg = m.group(); + if (arg.length() > 1 && (arg.charAt(0) == '"' || arg.charAt(0) == '\'')) { + arg = arg.substring(1, arg.length() - 1); + } + commandList.add(arg); } return compile(commandList.toArray(new String[commandList.size()]), env, outputFile, directory, onSuccess, onFailure, compilationOutput, synchronous); }