提交 f747bd20 authored 作者: Thomas Mueller's avatar Thomas Mueller

The function JAVADECODE ignored characters after a non-escaped double quote.…

The function JAVADECODE ignored characters after a non-escaped double quote. This is no longer the case.
上级 cff7158b
...@@ -226,11 +226,9 @@ public class StringUtils { ...@@ -226,11 +226,9 @@ public class StringUtils {
StringBuilder buff = new StringBuilder(length); StringBuilder buff = new StringBuilder(length);
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
char c = s.charAt(i); char c = s.charAt(i);
if (c == '"') { if (c == '\\') {
break; if (i + 1 >= s.length()) {
} else if (c == '\\') { throw getFormatException(s, i);
if (i >= s.length()) {
throw getFormatException(s, s.length() - 1);
} }
c = s.charAt(++i); c = s.charAt(++i);
switch (c) { switch (c) {
......
...@@ -125,6 +125,7 @@ public class TestStringUtils extends TestBase { ...@@ -125,6 +125,7 @@ public class TestStringUtils extends TestBase {
} }
private void testJavaString() { private void testJavaString() {
assertEquals("a\"b", StringUtils.javaDecode("a\"b"));
Random random = new Random(1); Random random = new Random(1);
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
int len = random.nextInt(10); int len = random.nextInt(10);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论