Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(path): Keypath should parse if sub path contains spaces. #533

Merged
merged 2 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ function getPathCharType (ch: ?string): string {
case 0x2D: // -
return 'ident'

case 0x20: // Space
case 0x09: // Tab
case 0x0A: // Newline
case 0x0D: // Return
Expand Down
7 changes: 7 additions & 0 deletions test/unit/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ describe('basic', () => {
it('should be translated', () => {
assert.strictEqual(i18n.t('message.format'), messages.en.message.format)
})

it('should be translated if keypath contains spaces', () => {
assert.strictEqual(
i18n.t('message.Hello {0}', ['kazupon']),
'Hello kazupon'
)
})
})

describe('array keypath', () => {
Expand Down
1 change: 1 addition & 0 deletions test/unit/fixture/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default {
circular2: 'Bar @:message.circular3',
circular3: 'Buz @:message.circular1',
linkTwice: '@:message.hello: @:message.hello',
'Hello {0}': 'Hello {0}',
'hyphen-locale': 'hello hyphen',
'1234': 'Number-based keys are found',
'1mixedKey': 'Mixed keys are not found.',
Expand Down
17 changes: 17 additions & 0 deletions test/unit/path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,28 @@ describe('path', () => {
})
})

describe('whitespace', () => {
it('should get value if it contains space 0x20', () => {
const val = path.getPathValue({ 'a c': 1 }, 'a c')
assert.strictEqual(val, 1)
})

it('should return null if it contains whitespace chars except space 0x20', () => {
const val = path.getPathValue({ 'a\tc': 1 }, 'a\tc')
assert.strictEqual(val, null)
})
})

describe('object', () => {
it('should get path value', () => {
const val = path.getPathValue({ a: { b: 1 } }, 'a')
assert.strictEqual(val.b, 1)
})

it('should accept space 0x20 as keypath', () => {
const val = path.getPathValue({ a: { 'b c d': 1 } }, 'a.b c d')
assert.strictEqual(val, 1)
})
})

describe('number key in object', () => {
Expand Down