Skip to content

Commit

Permalink
Merge pull request #896 from SpeedoDevo/master
Browse files Browse the repository at this point in the history
remove regex escape from format separators, fixes #895
  • Loading branch information
jamuhl committed Mar 10, 2017
2 parents 96501ad + 4295624 commit 58b46b9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Interpolator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class Interpolator {

this.prefix = iOpts.prefix ? utils.regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{';
this.suffix = iOpts.suffix ? utils.regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}';
this.formatSeparator = iOpts.formatSeparator ? utils.regexEscape(iOpts.formatSeparator) : iOpts.formatSeparator || ',';

this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';

this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-';
this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || '';
Expand Down
25 changes: 25 additions & 0 deletions test/interpolation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,31 @@ describe('Interpolator', () => {
});
});

describe('interpolate() - with formatter using a special formatSeparator', () => {
let ip;

before(() => {
ip = new Interpolator({
interpolation: {
formatSeparator: '|',
format: function(value, format, lng) {
if (format === 'uppercase') return value.toUpperCase();
return value;
}
}
});
});

var tests = [
{args: ['test {{test | uppercase}}', {test: 'up'}], expected: 'test UP'}
];

tests.forEach((test) => {
it('correctly interpolates for ' + JSON.stringify(test.args) + ' args', () => {
expect(ip.interpolate.apply(ip, test.args)).to.eql(test.expected);
});
});
});

describe('interpolate() - unescape', () => {
var ip;
Expand Down

0 comments on commit 58b46b9

Please sign in to comment.