From fc71eda19bf75ef69e08485170e4b68e9db7ea30 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sun, 9 Jul 2017 01:08:18 +0900 Subject: [PATCH] :bug: bug(format): fix cannot collectly parse percent close #191 --- src/format.js | 3 +++ test/unit/issues.test.js | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/format.js b/src/format.js index b0347f1a0..f0c095bc0 100644 --- a/src/format.js +++ b/src/format.js @@ -55,6 +55,9 @@ export function parse (format: string): Array { tokens.push({ value: sub, type }) } else if (char === '%') { // when found rails i18n syntax, skip text capture + if (format[(position)] !== '{') { + text += char + } } else { text += char } diff --git a/test/unit/issues.test.js b/test/unit/issues.test.js index 06d787770..6658c5036 100644 --- a/test/unit/issues.test.js +++ b/test/unit/issues.test.js @@ -1,4 +1,5 @@ import messages from './fixture/index' +import { parse } from '../../src/format' describe('issues', () => { let vm, i18n @@ -241,4 +242,15 @@ describe('issues', () => { }).then(done) }) }) + + describe('#191', () => { + it('should be parsed', () => { + const tokens = parse('{deposit}% PREPAYMENT') + assert(tokens.length === 2) + assert.equal(tokens[0].type, 'named') + assert.equal(tokens[0].value, 'deposit') + assert.equal(tokens[1].type, 'text') + assert.equal(tokens[1].value, '% PREPAYMENT') + }) + }) })