fix(NumberPipe): fix broken RegExp

introduced in 7498050421 (#9308)
This commit is contained in:
Victor Berchet 2016-06-17 15:15:15 -07:00
parent 773c34900f
commit 49bf3f5b3a
2 changed files with 3 additions and 3 deletions

View File

@ -5,7 +5,7 @@ import {NumberWrapper, RegExpWrapper, Type, isBlank, isNumber, isPresent} from '
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception'; import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
var defaultLocale: string = 'en-US'; var defaultLocale: string = 'en-US';
const _NUMBER_REGEXP = /^(\d+)?\.((\d+)(\-(\d+))?)?$'/g; const _NUMBER_FORMAT_REGEXP = /^(\d+)?\.((\d+)(\-(\d+))?)?$/g;
/** /**
* Internal function to format numbers used by Decimal, Percent and Date pipes. * Internal function to format numbers used by Decimal, Percent and Date pipes.
@ -19,7 +19,7 @@ function formatNumber(
} }
var minInt = 1, minFraction = 0, maxFraction = 3; var minInt = 1, minFraction = 0, maxFraction = 3;
if (isPresent(digits)) { if (isPresent(digits)) {
var parts = RegExpWrapper.firstMatch(_NUMBER_REGEXP, digits); var parts = RegExpWrapper.firstMatch(_NUMBER_FORMAT_REGEXP, digits);
if (isBlank(parts)) { if (isBlank(parts)) {
throw new BaseException(`${digits} is not a valid digit info for number pipes`); throw new BaseException(`${digits} is not a valid digit info for number pipes`);
} }

View File

@ -19,7 +19,6 @@ export function main() {
expect(pipe.transform(123, '.2')).toEqual('123.00'); expect(pipe.transform(123, '.2')).toEqual('123.00');
expect(pipe.transform(1, '3.')).toEqual('001'); expect(pipe.transform(1, '3.')).toEqual('001');
expect(pipe.transform(1.1, '3.4-5')).toEqual('001.1000'); expect(pipe.transform(1.1, '3.4-5')).toEqual('001.1000');
expect(pipe.transform(1.123456, '3.4-5')).toEqual('001.12346'); expect(pipe.transform(1.123456, '3.4-5')).toEqual('001.12346');
expect(pipe.transform(1.1234)).toEqual('1.123'); expect(pipe.transform(1.1234)).toEqual('1.123');
}); });
@ -54,6 +53,7 @@ export function main() {
it('should return correct value for numbers', () => { it('should return correct value for numbers', () => {
expect(pipe.transform(123)).toEqual('USD123'); expect(pipe.transform(123)).toEqual('USD123');
expect(pipe.transform(12, 'EUR', false, '.2')).toEqual('EUR12.00'); expect(pipe.transform(12, 'EUR', false, '.2')).toEqual('EUR12.00');
expect(pipe.transform(5.123, 'USD', false, '.0-2')).toEqual('USD5.12');
}); });
it('should not support other objects', it('should not support other objects',