From 6520f1e27af721dbcfb246cd9901268867b6f8ad Mon Sep 17 00:00:00 2001 From: Peter Dell Date: Sat, 3 Feb 2024 23:29:37 +0100 Subject: [PATCH] Fix escaping for regex split of spaces --- .../ide/lng/editor/LanguageEditorCompileCommand.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorCompileCommand.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorCompileCommand.java index 7e2c6db8..835c2b2b 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorCompileCommand.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditorCompileCommand.java @@ -186,9 +186,10 @@ final class LanguageEditorCompileCommand { throw new RuntimeException("Cannot show view.", ex); } } - + /** * Splits a string a one or more spaces, unless they are quoted. + * * @param commandLine The command line to be split, not null. * @return The array of string, may be empty, not null. */ @@ -196,7 +197,11 @@ final class LanguageEditorCompileCommand { if (commandLine == null) { throw new IllegalArgumentException("Parameter 'commandLine' must not be null."); } - return commandLine.split("\s+(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1); + return commandLine.split("\\s+(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1); + } + + public static void main(String[] args) { + System.out.println(java.util.Arrays.toString(splitAtSpaces("\"a b\" \"c d\" e"))); } private boolean executeInternal(ILanguageEditor languageEditor, CompilerFiles files, String commandId,