Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

Commit 640daaf

Browse files
exoegokazupon
authored andcommittedMar 14, 2019
⭐ new(path): Keypath should parse if sub path contains spaces. (#533) by @exoego
* feat(path): Keypath should parse if sub path contains spaces. * feat(path): Added test for whitespaces
1 parent 70eedb1 commit 640daaf

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed
 

‎src/path.js

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ function getPathCharType (ch: ?string): string {
122122
case 0x2D: // -
123123
return 'ident'
124124

125-
case 0x20: // Space
126125
case 0x09: // Tab
127126
case 0x0A: // Newline
128127
case 0x0D: // Return

‎test/unit/basic.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ describe('basic', () => {
105105
it('should be translated', () => {
106106
assert.strictEqual(i18n.t('message.format'), messages.en.message.format)
107107
})
108+
109+
it('should be translated if keypath contains spaces', () => {
110+
assert.strictEqual(
111+
i18n.t('message.Hello {0}', ['kazupon']),
112+
'Hello kazupon'
113+
)
114+
})
108115
})
109116

110117
describe('array keypath', () => {

‎test/unit/fixture/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default {
2828
circular2: 'Bar @:message.circular3',
2929
circular3: 'Buz @:message.circular1',
3030
linkTwice: '@:message.hello: @:message.hello',
31+
'Hello {0}': 'Hello {0}',
3132
'hyphen-locale': 'hello hyphen',
3233
'1234': 'Number-based keys are found',
3334
'1mixedKey': 'Mixed keys are not found.',

‎test/unit/path.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,28 @@ describe('path', () => {
99
})
1010
})
1111

12+
describe('whitespace', () => {
13+
it('should get value if it contains space 0x20', () => {
14+
const val = path.getPathValue({ 'a c': 1 }, 'a c')
15+
assert.strictEqual(val, 1)
16+
})
17+
18+
it('should return null if it contains whitespace chars except space 0x20', () => {
19+
const val = path.getPathValue({ 'a\tc': 1 }, 'a\tc')
20+
assert.strictEqual(val, null)
21+
})
22+
})
23+
1224
describe('object', () => {
1325
it('should get path value', () => {
1426
const val = path.getPathValue({ a: { b: 1 } }, 'a')
1527
assert.strictEqual(val.b, 1)
1628
})
29+
30+
it('should accept space 0x20 as keypath', () => {
31+
const val = path.getPathValue({ a: { 'b c d': 1 } }, 'a.b c d')
32+
assert.strictEqual(val, 1)
33+
})
1734
})
1835

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

0 commit comments

Comments
 (0)
This repository has been archived.