mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-13 10:29:35 +01:00
Fixed bug in StringReplacer
This commit is contained in:
parent
c32c3517a5
commit
f8ec9418d1
@ -57,8 +57,10 @@ public class StringReplacer {
|
||||
for (String i : src.split(" ")) {
|
||||
if (escapingChar == null) {
|
||||
// If the first char is not an escape char..
|
||||
String first = i.substring(0, 1);
|
||||
if (!quoteChars.contains(first)) {
|
||||
String first = null;
|
||||
if (i.length() > 0)
|
||||
first = i.substring(0, 1);
|
||||
if (first == null || !quoteChars.contains(first)) {
|
||||
if (i.trim().length() != 0 || acceptEmptyArguments)
|
||||
res.add(i);
|
||||
continue;
|
||||
|
29
app/test/processing/app/helpers/StringReplacerTest.java
Normal file
29
app/test/processing/app/helpers/StringReplacerTest.java
Normal file
@ -0,0 +1,29 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class StringReplacerTest {
|
||||
|
||||
@Test
|
||||
public void quotingCheck() throws Exception {
|
||||
String in = "a\"bc ab'c 'abc abc' ";
|
||||
in += "\"abc abc\" '\"abc abc\"' ";
|
||||
in += "\"'abc abc'\"";
|
||||
String[] res = StringReplacer.quotedSplit(in, "\"'", false);
|
||||
assertArrayEquals(res, new String[] { "a\"bc", "ab'c", "abc abc",
|
||||
"abc abc", "\"abc abc\"", "'abc abc'" });
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quotingCheckWithEmptyStringsAccepted() throws Exception {
|
||||
String in = "a\"bc ab'c 'abc abc' ";
|
||||
in += "\"abc abc\" '\"abc abc\"' ";
|
||||
in += "\"'abc abc'\"";
|
||||
String[] res = StringReplacer.quotedSplit(in, "\"'", true);
|
||||
assertArrayEquals(res, new String[] { "a\"bc", "ab'c", "", "", "abc abc",
|
||||
"abc abc", "\"abc abc\"", "'abc abc'" });
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user