From 27234a3328b93dd1e609f654ad0f3911bce9e0ec Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 10 Dec 2014 07:57:48 -0800 Subject: [PATCH 1/3] remove exception for incorrect shape, instead return nil --- project.clj | 2 +- src/json_path/walker.clj | 3 +-- .../META-INF/maven/json-path/json-path/pom.properties | 6 ++++++ target/stale/extract-native.dependencies | 1 + test/json_path/test/walker_test.clj | 4 ++-- 5 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 target/classes/META-INF/maven/json-path/json-path/pom.properties create mode 100644 target/stale/extract-native.dependencies diff --git a/project.clj b/project.clj index ba88995..6f3c1e8 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject json-path "0.3.0" +(defproject json-path "0.3.0-local" :description "JSON Path for Clojure data structures" :url "http://github.com/gga/json-path" :dependencies [[org.clojure/clojure "1.5.0"]] diff --git a/src/json_path/walker.clj b/src/json_path/walker.clj index 3dc5b75..2ac6a55 100644 --- a/src/json_path/walker.clj +++ b/src/json_path/walker.clj @@ -42,8 +42,7 @@ (let [sel (nth sel-expr 1)] (if (= "*" sel) (:current context) - (nth (:current context) (Integer/parseInt sel)))) - (throw (Exception. "object must be an array."))) + (nth (:current context) (Integer/parseInt sel))))) (= :filter (first sel-expr)) (filter #(eval-expr (nth sel-expr 1) (assoc context :current %)) (:current context)))) (defn walk [[opcode operand continuation] context] diff --git a/target/classes/META-INF/maven/json-path/json-path/pom.properties b/target/classes/META-INF/maven/json-path/json-path/pom.properties new file mode 100644 index 0000000..3dc53e1 --- /dev/null +++ b/target/classes/META-INF/maven/json-path/json-path/pom.properties @@ -0,0 +1,6 @@ +#Leiningen +#Wed Dec 10 07:08:54 PST 2014 +version=0.3.0-local +revision=43820df35b15309850e85c6bbccdbbb09b192b17\n +groupId=json-path +artifactId=json-path diff --git a/target/stale/extract-native.dependencies b/target/stale/extract-native.dependencies new file mode 100644 index 0000000..85456bd --- /dev/null +++ b/target/stale/extract-native.dependencies @@ -0,0 +1 @@ +([:dependencies ([org.clojure/clojure "1.5.0"])]) \ No newline at end of file diff --git a/test/json_path/test/walker_test.clj b/test/json_path/test/walker_test.clj index 4681743..63a123d 100644 --- a/test/json_path/test/walker_test.clj +++ b/test/json_path/test/walker_test.clj @@ -36,8 +36,8 @@ {:current [{:bar "wrong"} {:bar "baz"}]}) => [{:bar "baz"}]) (fact "selecting places constraints on the shape of the object being selected from" - (walk-selector [:index "1"] {:current {:foo "bar"}}) => (throws Exception) - (walk-selector [:index "*"] {:current {:foo "bar"}}) => (throws Exception)) + (walk-selector [:index "1"] {:current {:foo "bar"}}) => nil + (walk-selector [:index "*"] {:current {:foo "bar"}}) => nil) (facts (walk [:path [[:root]]] {:root ...json...}) => ...json... From e64be94f25ae82f1bebbf0866deaad7186e7d441 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 10 Dec 2014 10:39:35 -0800 Subject: [PATCH 2/3] handle out of bounds array references --- src/json_path/walker.clj | 2 +- .../classes/META-INF/maven/json-path/json-path/pom.properties | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/json_path/walker.clj b/src/json_path/walker.clj index 2ac6a55..3ca3d29 100644 --- a/src/json_path/walker.clj +++ b/src/json_path/walker.clj @@ -42,7 +42,7 @@ (let [sel (nth sel-expr 1)] (if (= "*" sel) (:current context) - (nth (:current context) (Integer/parseInt sel))))) + (nth (:current context) (Integer/parseInt sel) nil)))) (= :filter (first sel-expr)) (filter #(eval-expr (nth sel-expr 1) (assoc context :current %)) (:current context)))) (defn walk [[opcode operand continuation] context] diff --git a/target/classes/META-INF/maven/json-path/json-path/pom.properties b/target/classes/META-INF/maven/json-path/json-path/pom.properties index 3dc53e1..95459d0 100644 --- a/target/classes/META-INF/maven/json-path/json-path/pom.properties +++ b/target/classes/META-INF/maven/json-path/json-path/pom.properties @@ -1,6 +1,6 @@ #Leiningen -#Wed Dec 10 07:08:54 PST 2014 +#Wed Dec 10 10:37:16 PST 2014 version=0.3.0-local -revision=43820df35b15309850e85c6bbccdbbb09b192b17\n +revision=27234a3328b93dd1e609f654ad0f3911bce9e0ec\n groupId=json-path artifactId=json-path From 150f57fc690397afc6c0cf93beb07779e38ca01a Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 10 Dec 2014 11:01:31 -0800 Subject: [PATCH 3/3] mend --- .../META-INF/maven/json-path/json-path/pom.properties | 6 ------ target/stale/extract-native.dependencies | 1 - 2 files changed, 7 deletions(-) delete mode 100644 target/classes/META-INF/maven/json-path/json-path/pom.properties delete mode 100644 target/stale/extract-native.dependencies diff --git a/target/classes/META-INF/maven/json-path/json-path/pom.properties b/target/classes/META-INF/maven/json-path/json-path/pom.properties deleted file mode 100644 index 95459d0..0000000 --- a/target/classes/META-INF/maven/json-path/json-path/pom.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Leiningen -#Wed Dec 10 10:37:16 PST 2014 -version=0.3.0-local -revision=27234a3328b93dd1e609f654ad0f3911bce9e0ec\n -groupId=json-path -artifactId=json-path diff --git a/target/stale/extract-native.dependencies b/target/stale/extract-native.dependencies deleted file mode 100644 index 85456bd..0000000 --- a/target/stale/extract-native.dependencies +++ /dev/null @@ -1 +0,0 @@ -([:dependencies ([org.clojure/clojure "1.5.0"])]) \ No newline at end of file