diff --git a/src/ng/filter/filters.js b/src/ng/filter/filters.js index f0ef2f29d3aa..1c9007b8d79e 100644 --- a/src/ng/filter/filters.js +++ b/src/ng/filter/filters.js @@ -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); }; } diff --git a/test/ng/filter/filtersSpec.js b/test/ng/filter/filtersSpec.js index bdd9b81a2417..a2c4e009b5d1 100644 --- a/test/ng/filter/filtersSpec.js +++ b/test/ng/filter/filtersSpec.js @@ -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() {