]> granicus.if.org Git - icu/commitdiff
ICU-13115 Reject decimal format patterns that have a trailing ','
authorShane Carr <shane@unicode.org>
Wed, 19 Apr 2017 23:42:18 +0000 (23:42 +0000)
committerShane Carr <shane@unicode.org>
Wed, 19 Apr 2017 23:42:18 +0000 (23:42 +0000)
X-SVN-Rev: 40068

icu4c/source/test/testdata/numberformattestspecification.txt
icu4j/main/classes/core/src/com/ibm/icu/impl/number/PatternString.java
icu4j/main/tests/core/src/com/ibm/icu/dev/data/numberformattestspecification.txt
icu4j/main/tests/core/src/com/ibm/icu/dev/test/number/PatternStringTest.java

index 5c39853bc412b27887da9e199e2dde97d184db8e..9858ffe6995c537ee9bd9a22eda51a45210fe86b 100644 (file)
@@ -1534,10 +1534,9 @@ set locale en
 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
index 7540c89094079f4f33588312d43ad22e256abd69..c43f4a8df728823fc39f245023f687c194599ad8 100644 (file)
@@ -743,6 +743,7 @@ public class PatternString {
       boolean seenSignificantDigitMarker = false;
       boolean seenDigit = false;
 
+      outer:
       while (true) {
         switch (state.peek()) {
           case ',':
@@ -798,10 +799,18 @@ public class PatternString {
             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) {
index 5c39853bc412b27887da9e199e2dde97d184db8e..9858ffe6995c537ee9bd9a22eda51a45210fe86b 100644 (file)
@@ -1534,10 +1534,9 @@ set locale en
 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
index 1226ab92de088ee310e06a67ed5647bfccbe74f2..b9bf2efe97f2b51cf28c7816a6b0b51caa18ad41 100644 (file)
@@ -97,7 +97,9 @@ public class PatternStringTest {
 
   @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 {