begin
pattern format output breaks
$0M 123456 $123456M
-// C, J, and K reject the pattern as malformed.
-// S accepts it and prints no grouping.
-$0,M 123456 $123456M CJK
-$0,,M 123456 $123456M CJK
+// The following patterns are rejected as malformed.
+$0,M 123456 fail
+$0,,M 123456 fail
test empty negative subpattern
// This test is for #13117
boolean seenSignificantDigitMarker = false;
boolean seenDigit = false;
+ outer:
while (true) {
switch (state.peek()) {
case ',':
break;
default:
- return;
+ break outer;
}
state.next(); // consume the symbol
}
+
+ // Disallow patterns with a trailing ',' or with two ',' next to each other
+ if (result.groupingSizes[0] == 0 && result.groupingSizes[1] != -1) {
+ throw state.toParseException("Trailing grouping separator is invalid");
+ }
+ if (result.groupingSizes[1] == 0 && result.groupingSizes[2] != -1) {
+ throw state.toParseException("Grouping width of zero is invalid");
+ }
}
private static void consumeFractionFormat(ParserState state, SubpatternParseResult result) {
begin
pattern format output breaks
$0M 123456 $123456M
-// C, J, and K reject the pattern as malformed.
-// S accepts it and prints no grouping.
-$0,M 123456 $123456M CJK
-$0,,M 123456 $123456M CJK
+// The following patterns are rejected as malformed.
+$0,M 123456 fail
+$0,,M 123456 fail
test empty negative subpattern
// This test is for #13117
@Test
public void testExceptionOnInvalid() {
- String[] invalidPatterns = {"#.#.#", "0#", "0#.", ".#0", "0#.#0", "@0", "0@"};
+ String[] invalidPatterns = {
+ "#.#.#", "0#", "0#.", ".#0", "0#.#0", "@0", "0@", "0,", "0,,", "0,,0", "0,,0,"
+ };
for (String pattern : invalidPatterns) {
try {