diff --git a/src/number/parse-properties.js b/src/number/parse-properties.js index bdab525f0..604ceac85 100644 --- a/src/number/parse-properties.js +++ b/src/number/parse-properties.js @@ -121,8 +121,9 @@ return function( pattern, cldr, options ) { if ( !isNaN( minimumSignificantDigits * maximumSignificantDigits ) || /* 1 */ maximumFractionDigits /* 2 */ ) { + // 1: Handle trailing decimal separator, e.g., `"1." => `1``. aux = decimalSymbolRe + digitsRe + "+"; - numberTokenizer = numberTokenizer + "(" + aux + ")?" + + numberTokenizer = numberTokenizer + "(" + aux + "|" + decimalSymbolRe /* 1 */ + ")?" + // Handle non-padded decimals, e.g., `".12"` => `0.12` by making the integer part // optional. diff --git a/test/unit/number/parse-properties.js b/test/unit/number/parse-properties.js index 9c96bfdc6..4d37949da 100644 --- a/test/unit/number/parse-properties.js +++ b/test/unit/number/parse-properties.js @@ -91,26 +91,26 @@ QUnit.test( "should return negativeSuffix tokenizer", function( assert ) { QUnit.test( "should return number tokenizer", function( assert ) { assert.deepEqual( properties( "0", en )[ 2 ].number, /^\d+/ ); - assert.deepEqual( properties( "0.##", en )[ 2 ].number, /^(\d+(\.\d+)?|(\d+)?\.\d+)/ ); + assert.deepEqual( properties( "0.##", en )[ 2 ].number, /^(\d+(\.\d+|\.)?|(\d+)?\.\d+)/ ); assert.deepEqual( properties( "#,##0.##", en )[ 2 ].number, - /^((\d{1,3}(,\d{3})+|\d+)(\.\d+)?|((\d{1,3}(,\d{3})+|\d+))?\.\d+)/ + /^((\d{1,3}(,\d{3})+|\d+)(\.\d+|\.)?|((\d{1,3}(,\d{3})+|\d+))?\.\d+)/ ); assert.deepEqual( properties( "#,##0.##", es )[ 2 ].number, - /^((\d{1,3}(\.\d{3})+|\d+)(,\d+)?|((\d{1,3}(\.\d{3})+|\d+))?,\d+)/ + /^((\d{1,3}(\.\d{3})+|\d+)(,\d+|,)?|((\d{1,3}(\.\d{3})+|\d+))?,\d+)/ ); assert.deepEqual( properties( "#,##,##0.##", en )[ 2 ].number, - /^((\d{1,2}((,\d{2})*(,\d{3}))|\d+)(\.\d+)?|((\d{1,2}((,\d{2})*(,\d{3}))|\d+))?\.\d+)/ + /^((\d{1,2}((,\d{2})*(,\d{3}))|\d+)(\.\d+|\.)?|((\d{1,2}((,\d{2})*(,\d{3}))|\d+))?\.\d+)/ ); assert.deepEqual( properties( "#,##0.##", sv )[ 2 ].number, - /^((\d{1,3}( \d{3})+|\d+)(,\d+)?|((\d{1,3}( \d{3})+|\d+))?,\d+)/ + /^((\d{1,3}( \d{3})+|\d+)(,\d+|,)?|((\d{1,3}( \d{3})+|\d+))?,\d+)/ ); }); diff --git a/test/unit/number/parse.js b/test/unit/number/parse.js index 87a281c5e..7e33dae95 100644 --- a/test/unit/number/parse.js +++ b/test/unit/number/parse.js @@ -109,6 +109,12 @@ QUnit.test( "should parse zero-padded decimals", function( assert ) { assert.equal( parse( "0.10", properties( "0.00", en ) ), 0.1 ); }); +QUnit.test( "should parse trailing decimal separator", function( assert ) { + assert.equal( parse( "1.", properties( "0.0", en ) ), 1 ); + assert.equal( parse( "١٫", properties( "0.0", ar ) ), 1 ); + assert.equal( parse( "1,", properties( "0.0", pt ) ), 1 ); +}); + QUnit.test( "should parse non-padded decimals", function( assert ) { assert.equal( parse( ".14159", properties( "0.0", en ) ), 0.14159 ); assert.equal( parse( ".752", properties( "0.0", en ) ), 0.752 );