diff --git a/Cargo.toml b/Cargo.toml index afda4ad..63d167d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "jsonpath_lib" -version = "0.2.2" +version = "0.2.3" authors = ["Changseok Han "] -description = "It is JsonPath engine written in Rust. it provide a similar API interface in Webassembly and Javascript also. - Webassembly Demo: https://freestrings.github.io/jsonpath" +description = "It is JsonPath engine written in Rust. it provide a similar API interface in Webassembly and Javascript too. - Webassembly Demo: https://freestrings.github.io/jsonpath" readme = "README.md" keywords = ["jsonpath", "json", "webassembly", "nodejs", "javascript"] @@ -19,11 +19,10 @@ travis-ci = { repository = "freestrings/jsonpath", branch = "master" } [dependencies] log = "0.4" -env_logger = "0.6.0" +env_logger = "0.6" serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0", features = ["preserve_order"] } -indexmap = "1.0.2" -array_tool = "~1.0.3" +array_tool = "1.0.3" [dev-dependencies] bencher = "0.1.5" diff --git a/README.md b/README.md index 594c7bc..eac2230 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ `Rust` 버전 [JsonPath](https://goessner.net/articles/JsonPath/) 구현이다. `Webassembly`와 `Javascript`에서도 유사한 API 인터페이스를 제공 한다. -It is JsonPath [JsonPath](https://goessner.net/articles/JsonPath/) engine written in `Rust`. it provide a similar API interface in `Webassembly` and` Javascript` also. +It is JsonPath [JsonPath](https://goessner.net/articles/JsonPath/) engine written in `Rust`. it provide a similar API interface in `Webassembly` and` Javascript` too. - [Webassembly Demo](https://freestrings.github.io/jsonpath/) - [NPM jsonpath-wasm - webassembly](https://www.npmjs.com/package/jsonpath-wasm) diff --git a/nodejs/native/Cargo.toml b/nodejs/native/Cargo.toml index 74fd4b6..70f33a4 100644 --- a/nodejs/native/Cargo.toml +++ b/nodejs/native/Cargo.toml @@ -14,7 +14,7 @@ exclude = ["artifacts.json", "index.node"] neon-build = "0.2.0" [dependencies] -jsonpath_lib = "0.2.2" +jsonpath_lib = "0.2.3" #jsonpath_lib = { path = "../../" } neon = "0.2.0" serde_json = { version = "1.0", features = ["preserve_order"] } diff --git a/nodejs/test/index.spec.js b/nodejs/test/index.spec.js index 8a1760d..9d4721d 100644 --- a/nodejs/test/index.spec.js +++ b/nodejs/test/index.spec.js @@ -894,35 +894,35 @@ describe('ISSUE test', () => { } }); - // it('Invalid wildcard filter results #7', (done) => { - // - // function select(json, expected, paths) { - // for (var i = 0 ; i < paths.length ; i++) { - // let result = jsonpath.select(json, paths[i]); - // if (JSON.stringify(result) !== JSON.stringify(expected)) { - // throw Error("Error: " + paths[i]); - // } - // } - // } - // - // select( - // ["string", 42, { "key": "value" }, [0, 1]], - // ["string", 42, { "key": "value" }, [0, 1]], - // ["$.*", "$[*]"] - // ); - // - // select( - // ["string", 42, { "key": "value" }, [0, 1]], - // [ "string", 42, { "key" : "value" }, [ 0, 1 ], "value", 0, 1 ], - // ["$..*", "$..[*]"] - // ); - // - // select( - // ["string", 42, { "key": "value" }, [0, 1]], - // ["value", 0, 1], - // ["$.*.*", "$[*].*", "$.*[*]", "$[*][*]"] - // ); - // - // done(); - // }); + it('Invalid wildcard filter results #7', (done) => { + + function select(json, expected, paths) { + for (var i = 0 ; i < paths.length ; i++) { + let result = jsonpath.select(json, paths[i]); + if (JSON.stringify(result) !== JSON.stringify(expected)) { + throw Error("Error: " + paths[i]); + } + } + } + + select( + ["string", 42, { "key": "value" }, [0, 1]], + ["string", 42, { "key": "value" }, [0, 1]], + ["$.*", "$[*]"] + ); + + select( + ["string", 42, { "key": "value" }, [0, 1]], + [ "string", 42, { "key" : "value" }, [ 0, 1 ], "value", 0, 1 ], + ["$..*", "$..[*]"] + ); + + select( + ["string", 42, { "key": "value" }, [0, 1]], + ["value", 0, 1], + ["$.*.*", "$[*].*", "$.*[*]", "$[*][*]"] + ); + + done(); + }); }); \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 5782692..7864342 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -125,7 +125,6 @@ extern crate array_tool; extern crate core; extern crate env_logger; -extern crate indexmap; #[macro_use] extern crate log; extern crate serde; diff --git a/src/select/mod.rs b/src/select/mod.rs index bb94745..7713703 100644 --- a/src/select/mod.rs +++ b/src/select/mod.rs @@ -2,7 +2,6 @@ use std::collections::HashSet; use std::fmt; use array_tool::vec::{Intersect, Union}; -use indexmap::IndexMap; use serde_json::{Number, Value}; use parser::parser::*; @@ -1167,7 +1166,8 @@ impl SelectorMut { origin: &Value, target: &mut Vec<&Value>, tokens: &mut Vec, - visited: &mut IndexMap<*const Value, Vec>, + visited: &mut HashSet<*const Value>, + visited_order: &mut Vec>, ) -> bool { trace!("{:?}, {:?}", target, tokens); @@ -1177,7 +1177,9 @@ impl SelectorMut { target.retain(|t| { if std::ptr::eq(origin, *t) { - visited.insert(*t, tokens.to_vec()); + if visited.insert(*t) { + visited_order.push(tokens.to_vec()); + } false } else { true @@ -1188,7 +1190,7 @@ impl SelectorMut { Value::Array(vec) => { for (i, v) in vec.iter().enumerate() { tokens.push(i.to_string()); - if _walk(v, target, tokens, visited) { + if _walk(v, target, tokens, visited, visited_order) { return true; } tokens.pop(); @@ -1197,7 +1199,7 @@ impl SelectorMut { Value::Object(map) => { for (k, v) in map { tokens.push(k.clone()); - if _walk(v, target, tokens, visited) { + if _walk(v, target, tokens, visited, visited_order) { return true; } tokens.pop(); @@ -1209,14 +1211,21 @@ impl SelectorMut { return false; } - let mut visited = IndexMap::new(); + let mut visited = HashSet::new(); + let mut visited_order = Vec::new(); if let Some(origin) = &self.value { let mut tokens = Vec::new(); - _walk(origin, &mut result, &mut tokens, &mut visited); + _walk( + origin, + &mut result, + &mut tokens, + &mut visited, + &mut visited_order, + ); } - visited.iter().map(|(_, v)| v.to_vec()).collect() + visited_order } pub fn delete(&mut self) -> Result<&mut Self, JsonPathError> { diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index 5517b21..43b502d 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jsonpath-wasm" -version = "0.2.2" +version = "0.2.3" authors = ["Changseok Han "] description = "It is Webassembly version of jsonpath_lib that is JsonPath engine written in Rust - Demo: https://freestrings.github.io/jsonpath" keywords = ["jsonpath", "json", "webassembly", "parsing", "rust"] @@ -14,10 +14,10 @@ crate-type = ["cdylib", "rlib"] default = ["console_error_panic_hook", "wee_alloc"] [dependencies] -cfg-if = "0.1.2" +cfg-if = "0.1" wasm-bindgen = { version = "0.2", features = ["serde-serialize"] } -console_error_panic_hook = { version = "0.1.1", optional = true } -wee_alloc = { version = "0.4.2", optional = true } +console_error_panic_hook = { version = "0.1", optional = true } +wee_alloc = { version = "0.4", optional = true } jsonpath_lib = { path = "../" } serde = "1.0"