Kaynağa Gözat

path parser minor tweaks

Evan You 11 yıl önce
ebeveyn
işleme
31fd2087b6
2 değiştirilmiş dosya ile 12 ekleme ve 11 silme
  1. 11 11
      src/parsers/path.js
  2. 1 0
      test/unit/specs/parsers/path_spec.js

+ 11 - 11
src/parsers/path.js

@@ -90,7 +90,7 @@ pathStateMachine[IN_SUB_PATH] = {
   'ident': [IN_SUB_PATH, APPEND],
   '0': [IN_SUB_PATH, APPEND],
   'number': [IN_SUB_PATH, APPEND],
-  'ws': [AFTER_ELEMENT, PUSH],
+  'ws': [AFTER_ELEMENT],
   ']': [IN_PATH, PUSH]
 }
 
@@ -99,8 +99,6 @@ pathStateMachine[AFTER_ELEMENT] = {
   ']': [IN_PATH, PUSH]
 }
 
-function noop () {}
-
 /**
  * Determine the type of a character in a keypath.
  *
@@ -213,14 +211,16 @@ function parsePath (path) {
     }
 
     mode = transition[0]
-    action = actions[transition[1]] || noop
-    newChar = transition[2]
-    newChar = newChar === undefined
-      ? c
-      : newChar === '*'
-        ? newChar + c
-        : newChar
-    action()
+    action = actions[transition[1]]
+    if (action) {
+      newChar = transition[2]
+      newChar = newChar === undefined
+        ? c
+        : newChar === '*'
+          ? newChar + c
+          : newChar
+      action()
+    }
 
     if (mode === AFTER_PATH) {
       keys.raw = path

+ 1 - 0
test/unit/specs/parsers/path_spec.js

@@ -45,6 +45,7 @@ describe('Path Parser', function () {
     assertPath('foo["b\\"az"]', ['foo', 'b"az'])
     assertPath("foo['b\\'az']", ['foo', "b'az"])
     assertPath('a[b][c]', ['a', '*b', '*c'])
+    assertPath('a[ b ][ c ]', ['a', '*b', '*c'])
   })
 
   it('handle invalid paths', function () {