Skip to content

Commit 31fd208

Browse files
committed
path parser minor tweaks
1 parent 149df13 commit 31fd208

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/parsers/path.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pathStateMachine[IN_SUB_PATH] = {
9090
'ident': [IN_SUB_PATH, APPEND],
9191
'0': [IN_SUB_PATH, APPEND],
9292
'number': [IN_SUB_PATH, APPEND],
93-
'ws': [AFTER_ELEMENT, PUSH],
93+
'ws': [AFTER_ELEMENT],
9494
']': [IN_PATH, PUSH]
9595
}
9696

@@ -99,8 +99,6 @@ pathStateMachine[AFTER_ELEMENT] = {
9999
']': [IN_PATH, PUSH]
100100
}
101101

102-
function noop () {}
103-
104102
/**
105103
* Determine the type of a character in a keypath.
106104
*
@@ -213,14 +211,16 @@ function parsePath (path) {
213211
}
214212

215213
mode = transition[0]
216-
action = actions[transition[1]] || noop
217-
newChar = transition[2]
218-
newChar = newChar === undefined
219-
? c
220-
: newChar === '*'
221-
? newChar + c
222-
: newChar
223-
action()
214+
action = actions[transition[1]]
215+
if (action) {
216+
newChar = transition[2]
217+
newChar = newChar === undefined
218+
? c
219+
: newChar === '*'
220+
? newChar + c
221+
: newChar
222+
action()
223+
}
224224

225225
if (mode === AFTER_PATH) {
226226
keys.raw = path

test/unit/specs/parsers/path_spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe('Path Parser', function () {
4545
assertPath('foo["b\\"az"]', ['foo', 'b"az'])
4646
assertPath("foo['b\\'az']", ['foo', "b'az"])
4747
assertPath('a[b][c]', ['a', '*b', '*c'])
48+
assertPath('a[ b ][ c ]', ['a', '*b', '*c'])
4849
})
4950

5051
it('handle invalid paths', function () {

0 commit comments

Comments
 (0)