mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't escape already escaped additional characters when escapeSlash is false
This commit is contained in:
@@ -570,6 +570,7 @@ public class StringUtil {
|
||||
@Nullable String additionalChars,
|
||||
boolean escapeSlash,
|
||||
@NotNull @NonNls StringBuilder buffer) {
|
||||
char prev = 0;
|
||||
for (int idx = 0; idx < length; idx++) {
|
||||
char ch = str.charAt(idx);
|
||||
switch (ch) {
|
||||
@@ -597,7 +598,7 @@ public class StringUtil {
|
||||
if (escapeSlash && ch == '\\') {
|
||||
buffer.append("\\\\");
|
||||
}
|
||||
else if (additionalChars != null && additionalChars.indexOf(ch) > -1) {
|
||||
else if (additionalChars != null && additionalChars.indexOf(ch) > -1 && (escapeSlash || prev != '\\')) {
|
||||
buffer.append("\\").append(ch);
|
||||
}
|
||||
else if (Character.isISOControl(ch)) {
|
||||
@@ -613,6 +614,7 @@ public class StringUtil {
|
||||
buffer.append(ch);
|
||||
}
|
||||
}
|
||||
prev = ch;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@@ -111,4 +111,10 @@ public class StringUtilTest extends TestCase {
|
||||
public void testTitleCase() {
|
||||
assertEquals("Couldn't Connect to Debugger", StringUtil.wordsToBeginFromUpperCase("Couldn't connect to debugger"));
|
||||
}
|
||||
|
||||
public void testEscapeStringCharacters() {
|
||||
assertEquals("\\\"\\n", StringUtil.escapeStringCharacters(3, "\\\"\n", "\"", false, new StringBuilder()).toString());
|
||||
assertEquals("\\\"\\n", StringUtil.escapeStringCharacters(2, "\"\n", "\"", false, new StringBuilder()).toString());
|
||||
assertEquals("\\\\\\\"\\n", StringUtil.escapeStringCharacters(3, "\\\"\n", "\"", true, new StringBuilder()).toString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user