Skip to content
Permalink
Browse files

fix(common): remove trailing whitespace for CurrencyPipe (#34642)

Trimming any surrounding whitespace characters informatNumberToLocaleString
if currency symbol issupressed.

Closes #34641

PR Close #34642
  • Loading branch information
troelslenda authored and alxhub committed Jan 5, 2020
1 parent 17801c3 commit c42b90b81db36bd6d29f30164226fcfb9ead861c
Showing with 11 additions and 1 deletion.
  1. +6 −1 packages/common/src/i18n/format_number.ts
  2. +5 −0 packages/common/test/pipes/number_pipe_spec.ts
@@ -161,7 +161,12 @@ export function formatCurrency(
return res
.replace(CURRENCY_CHAR, currency)
// if we have 2 time the currency character, the second one is ignored
.replace(CURRENCY_CHAR, '');
.replace(CURRENCY_CHAR, '')
// If there is a spacing between currency character and the value and
// the currency character is supressed by passing an empty string, the
// spacing character would remain as part of the string. Then we
// should remove it.
.trim();
}

/**
@@ -11,6 +11,7 @@ import localeEsUS from '@angular/common/locales/es-US';
import localeFr from '@angular/common/locales/fr';
import localeAr from '@angular/common/locales/ar';
import localeDeAt from '@angular/common/locales/de-AT';
import localeDa from '@angular/common/locales/da';
import {ɵunregisterLocaleData, ɵregisterLocaleData} from '@angular/core';
import {CurrencyPipe, DecimalPipe, PercentPipe} from '@angular/common';
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
@@ -23,6 +24,7 @@ import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testin
ɵregisterLocaleData(localeFr);
ɵregisterLocaleData(localeAr);
ɵregisterLocaleData(localeDeAt);
ɵregisterLocaleData(localeDa);
});

afterAll(() => ɵunregisterLocaleData());
@@ -95,6 +97,7 @@ import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testin
expect(pipe.transform(12, 'EUR', 'code', '.1')).toEqual('EUR12.0');
expect(pipe.transform(5.1234, 'USD', 'code', '.0-3')).toEqual('USD5.123');
expect(pipe.transform(5.1234, 'USD', 'code')).toEqual('USD5.12');
expect(pipe.transform(5.1234, 'USD', '')).toEqual('5.12');
expect(pipe.transform(5.1234, 'USD', 'symbol')).toEqual('$5.12');
expect(pipe.transform(5.1234, 'CAD', 'symbol')).toEqual('CA$5.12');
expect(pipe.transform(5.1234, 'CAD', 'symbol-narrow')).toEqual('$5.12');
@@ -104,6 +107,8 @@ import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testin
expect(pipe.transform(5, 'USD', 'symbol', '', 'fr')).toEqual('5,00 $US');
expect(pipe.transform(123456789, 'EUR', 'symbol', '', 'de-at'))
.toEqual('€ 123.456.789,00');
expect(pipe.transform(5.1234, 'EUR', '', '', 'de-at')).toEqual('5,12');
expect(pipe.transform(5.1234, 'DKK', '', '', 'da')).toEqual('5,12');
});

it('should support any currency code name', () => {

0 comments on commit c42b90b

Please sign in to comment.
You can’t perform that action at this time.