Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

feat(currencyFilter): trim whitespace around an empty currency symbol #15105

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ng/filter/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ function currencyFilter($locale) {
fractionSize = formats.PATTERNS[1].maxFrac;
}

// If the currency symbol is empty, trim whitespace around the symbol
var currencySymbolRe = !currencySymbol ? /\s*\u00A4\s*/g : /\u00A4/g;

// if null or undefined pass it through
return (amount == null)
? amount
: formatNumber(amount, formats.PATTERNS[1], formats.GROUP_SEP, formats.DECIMAL_SEP, fractionSize).
replace(/\u00A4/g, currencySymbol);
replace(currencySymbolRe, currencySymbol);
};
}

Expand Down
13 changes: 13 additions & 0 deletions test/ng/filter/filtersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ describe('filters', function() {

expect(currency(1.07)).toBe('$1.1');
}));

it('should trim whitespace around the currency symbol if it is empty',
inject(function($locale) {
var pattern = $locale.NUMBER_FORMATS.PATTERNS[1];
pattern.posPre = pattern.posSuf = ' \u00A4 ';
pattern.negPre = pattern.negSuf = ' - \u00A4 - ';

expect(currency(+1.07, '$')).toBe(' $ 1.07 $ ');
expect(currency(-1.07, '$')).toBe(' - $ - 1.07 - $ - ');
expect(currency(+1.07, '')).toBe('1.07');
expect(currency(-1.07, '')).toBe(' -- 1.07 -- ');
})
);
});

describe('number', function() {
Expand Down