Skip to content

Commit

Permalink
fix(intl-messageformat): fix formatHTMLMessage @ regex
Browse files Browse the repository at this point in the history
  • Loading branch information
longlho committed Oct 23, 2019
1 parent 22121b2 commit d1b7c8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/intl-messageformat/src/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export type FormatXMLElementFn = (...args: any[]) => string | object;
// Singleton
let domParser: DOMParser;
const TOKEN_DELIMITER = '@@';
const TOKEN_REGEX = /@@(.*?)@@/g;
const TOKEN_REGEX = /@@(\d+_\d+)@@/g;
let counter = 0;
function generateId() {
return `${Date.now()}_${++counter}`;
Expand Down
9 changes: 9 additions & 0 deletions packages/intl-messageformat/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,15 @@ describe('IntlMessageFormat', function() {
});

describe('xml', function() {
it('should handle @ correctly', function() {
const mf = new IntlMessageFormat('hi @{there}', 'en');
expect(
mf.formatHTMLMessage({
there: '2008',
})
).to.deep.equal(['hi @2008']);
});

it('simple message', function() {
var mf = new IntlMessageFormat('hello <b>world</b>', 'en');
expect(mf.formatHTMLMessage({b: str => ({str})})).to.deep.equal([
Expand Down

0 comments on commit d1b7c8c

Please sign in to comment.