ICU-12979 Fix \Q...\E in UnicodeRegex#transform (#23)

This commit is contained in:
David Corbett 2018-09-10 18:19:10 -04:00 committed by Shane Carr
parent 00ccb44a30
commit 378b04c1b2
No known key found for this signature in database
GPG Key ID: FCED3B24AAB18B5C
2 changed files with 27 additions and 3 deletions

View File

@ -116,7 +116,7 @@ public class UnicodeRegex implements Cloneable, Freezable<UnicodeRegex>, StringT
case 1: // we are after a \
if (ch == 'Q') {
state = 1;
state = 2;
} else {
state = 0;
}
@ -128,11 +128,12 @@ public class UnicodeRegex implements Cloneable, Freezable<UnicodeRegex>, StringT
}
break;
case 3: // we are in at \Q...\
case 3: // we are in a \Q...\
if (ch == 'E') {
state = 0;
} else if (ch != '\\') {
state = 2;
}
state = 2;
break;
}
result.append(ch);

View File

@ -216,6 +216,29 @@ public class RegexUtilitiesTest extends TestFmwk {
}
}
/**
* Check {@code \Q} and {@code \E}.
*/
@Test
public void TestTransformQuotation() {
String[][] tests = {
{"a\\Qb", "a\\Qb"},
{"a\\Eb", "a\\Eb"},
{"\\Q[ba]", "\\Q[ba]"},
{"\\\\Q[ba]", "\\\\Q[ab]"},
{"\\Q[ba]\\e[ba]", "\\Q[ba]\\e[ba]"},
{"\\Q[ba]\\E[ba]", "\\Q[ba]\\E[ab]"},
{"\\Q[ba]\\\\E[ba]", "\\Q[ba]\\\\E[ab]"},
};
UnicodeRegex regex = new UnicodeRegex();
for (int i = 0; i < tests.length; ++i) {
final String source = tests[i][0];
String expected = tests[i][1];
String actual = regex.transform(source);
assertEquals(source, expected, actual);
}
}
/**
* Utility for checking patterns
*/