mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-20073 Do not parse stray percent sign in strict mode. (#145)
This commit is contained in:
parent
05d8814c2b
commit
e5bca0c9f7
5 changed files with 29 additions and 5 deletions
|
@ -159,10 +159,10 @@ NumberParserImpl::createParserFromProperties(const number::impl::DecimalFormatPr
|
|||
|
||||
// ICU-TC meeting, April 11, 2018: accept percent/permille only if it is in the pattern,
|
||||
// and to maintain regressive behavior, divide by 100 even if no percent sign is present.
|
||||
if (affixProvider->containsSymbolType(AffixPatternType::TYPE_PERCENT, status)) {
|
||||
if (!isStrict && affixProvider->containsSymbolType(AffixPatternType::TYPE_PERCENT, status)) {
|
||||
parser->addMatcher(parser->fLocalMatchers.percent = {symbols});
|
||||
}
|
||||
if (affixProvider->containsSymbolType(AffixPatternType::TYPE_PERMILLE, status)) {
|
||||
if (!isStrict && affixProvider->containsSymbolType(AffixPatternType::TYPE_PERMILLE, status)) {
|
||||
parser->addMatcher(parser->fLocalMatchers.permille = {symbols});
|
||||
}
|
||||
|
||||
|
|
|
@ -202,6 +202,7 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n
|
|||
TESTCASE_AUTO(Test11645_ApplyPatternEquality);
|
||||
TESTCASE_AUTO(Test12567);
|
||||
TESTCASE_AUTO(Test11626_CustomizeCurrencyPluralInfo);
|
||||
TESTCASE_AUTO(Test20073_StrictPercentParseErrorIndex);
|
||||
TESTCASE_AUTO(Test13056_GroupingSize);
|
||||
TESTCASE_AUTO(Test11025_CurrencyPadding);
|
||||
TESTCASE_AUTO(Test11648_ExpDecFormatMalPattern);
|
||||
|
@ -8942,6 +8943,17 @@ void NumberFormatTest::Test11626_CustomizeCurrencyPluralInfo() {
|
|||
assertEquals("Plural other", u"99 америчких долара", df.format(99, result.remove(), errorCode));
|
||||
}
|
||||
|
||||
void NumberFormatTest::Test20073_StrictPercentParseErrorIndex() {
|
||||
IcuTestErrorCode status(*this, "Test20073_StrictPercentParseErrorIndex");
|
||||
ParsePosition parsePosition(0);
|
||||
DecimalFormat df(u"0%", {"en-us", status}, status);
|
||||
df.setLenient(FALSE);
|
||||
Formattable result;
|
||||
df.parse(u"%2%", result, parsePosition);
|
||||
assertEquals("", 0, parsePosition.getIndex());
|
||||
assertEquals("", 0, parsePosition.getErrorIndex());
|
||||
}
|
||||
|
||||
void NumberFormatTest::Test13056_GroupingSize() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
DecimalFormat df(u"#,##0", status);
|
||||
|
|
|
@ -266,6 +266,7 @@ class NumberFormatTest: public CalendarTimeZoneTest {
|
|||
void Test11645_ApplyPatternEquality();
|
||||
void Test12567();
|
||||
void Test11626_CustomizeCurrencyPluralInfo();
|
||||
void Test20073_StrictPercentParseErrorIndex();
|
||||
void Test13056_GroupingSize();
|
||||
void Test11025_CurrencyPadding();
|
||||
void Test11648_ExpDecFormatMalPattern();
|
||||
|
|
|
@ -209,10 +209,10 @@ public class NumberParserImpl {
|
|||
|
||||
// ICU-TC meeting, April 11, 2018: accept percent/permille only if it is in the pattern,
|
||||
// and to maintain regressive behavior, divide by 100 even if no percent sign is present.
|
||||
if (affixProvider.containsSymbolType(AffixUtils.TYPE_PERCENT)) {
|
||||
if (!isStrict && affixProvider.containsSymbolType(AffixUtils.TYPE_PERCENT)) {
|
||||
parser.addMatcher(PercentMatcher.getInstance(symbols));
|
||||
}
|
||||
if (affixProvider.containsSymbolType(AffixUtils.TYPE_PERMILLE)) {
|
||||
if (!isStrict && affixProvider.containsSymbolType(AffixUtils.TYPE_PERMILLE)) {
|
||||
parser.addMatcher(PermilleMatcher.getInstance(symbols));
|
||||
}
|
||||
|
||||
|
@ -274,7 +274,7 @@ public class NumberParserImpl {
|
|||
* The parser settings defined in the PARSE_FLAG_* fields.
|
||||
*/
|
||||
public NumberParserImpl(int parseFlags) {
|
||||
matchers = new ArrayList<NumberParseMatcher>();
|
||||
matchers = new ArrayList<>();
|
||||
this.parseFlags = parseFlags;
|
||||
frozen = false;
|
||||
}
|
||||
|
|
|
@ -5990,6 +5990,17 @@ public class NumberFormatTest extends TestFmwk {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Test20073_StrictPercentParseErrorIndex() {
|
||||
ParsePosition parsePosition = new ParsePosition(0);
|
||||
DecimalFormat df = new DecimalFormat("0%", DecimalFormatSymbols.getInstance(Locale.US));
|
||||
df.setParseStrict(true);
|
||||
Number number = df.parse("%2%", parsePosition);
|
||||
assertNull("", number);
|
||||
assertEquals("", 0, parsePosition.getIndex());
|
||||
assertEquals("", 0, parsePosition.getErrorIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Test11626_CustomizeCurrencyPluralInfo() throws ParseException {
|
||||
// Use locale sr because it has interesting plural rules.
|
||||
|
|
Loading…
Add table
Reference in a new issue