Skip to content

Commit

Permalink
🐛 bug(format): Should warn as unknown if named format is not closed. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
TATSUNO Yasuhiro authored and kazupon committed Oct 12, 2018
1 parent 94583e5 commit d1f6ed0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ export function parse (format: string): Array<Token> {
text = ''
let sub: string = ''
char = format[position++]
while (char !== '}') {
while (char !== undefined && char !== '}') {
sub += char
char = format[position++]
}
const isClosed = char === '}'

const type = RE_TOKEN_LIST_VALUE.test(sub)
? 'list'
: RE_TOKEN_NAMED_VALUE.test(sub)
: isClosed && RE_TOKEN_NAMED_VALUE.test(sub)
? 'named'
: 'unknown'
tokens.push({ value: sub, type })
Expand Down
8 changes: 8 additions & 0 deletions test/unit/format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ describe('compile', () => {
assert.equal(compiled[2], ', age: ')
assert.equal(compiled[3], '0x20')
})

it('should be compiled as unknown if not closed', () => {
const tokens = parse('name: {name')
const compiled = compile(tokens, { name: 'kazupon' })
assert(compiled.length === 1)
assert.equal(compiled[0], 'name: ')
})
})

describe('unknown token', () => {
Expand All @@ -103,6 +110,7 @@ describe('compile', () => {
})
})


describe('values unknown mode', () => {
it('should be compiled with empty', () => {
const compiled = compile([], 1)
Expand Down

0 comments on commit d1f6ed0

Please sign in to comment.