Skip to content

Commit c1e3221

Browse files
besokBoris Zhguchev
andauthored
Feature/63 quotes (#65)
* add debug for Finder * add debug for Finder * add support for double qs * disable warning --------- Co-authored-by: Boris Zhguchev <[email protected]>
1 parent fc6964f commit c1e3221

File tree

6 files changed

+49
-33
lines changed

6 files changed

+49
-33
lines changed

CHANGELOG.md

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,48 @@
11
* **`0.1.0`**
2-
* Initial implementation
2+
* Initial implementation
33
* **`0.1.1`**
4-
* Technical improvements
4+
* Technical improvements
55
* **`0.1.2`**
6-
* added a trait to obtain the result from value
7-
* added a method to get the cloned as Value
8-
* change the name of the general method*
6+
* added a trait to obtain the result from value
7+
* added a method to get the cloned as Value
8+
* change the name of the general method*
99
* **`0.1.4`**
10-
* add an ability to use references instead of values
11-
* fix some clippy issues
10+
* add an ability to use references instead of values
11+
* fix some clippy issues
1212
* **`0.1.5`**
13-
* correct grammar for `$.[..]`
13+
* correct grammar for `$.[..]`
1414
* **`0.1.6`**
15-
* add logical OR and logical And to filters
16-
* fix bugs with objects in filters
17-
* add internal macros to generate path objects
15+
* add logical OR and logical And to filters
16+
* fix bugs with objects in filters
17+
* add internal macros to generate path objects
1818
* **`0.2.0`**
19-
* add json path value as a result for the library
20-
* add functions (size)
21-
* change a logical operator `size` into function `size()`
19+
* add json path value as a result for the library
20+
* add functions (size)
21+
* change a logical operator `size` into function `size()`
2222
* **`0.2.1`**
23-
* changed the contract for length() function.
23+
* changed the contract for length() function.
2424
* **`0.2.2`**
25-
* add ..*
25+
* add ..*
2626
* **`0.2.5`**
27-
* build for tags
27+
* build for tags
2828
* **`0.2.6`**
29-
* make parser mod public
29+
* make parser mod public
3030
* **`0.3.0`**
31-
* introduce the different behaviour for empty results and non-existing result
31+
* introduce the different behaviour for empty results and non-existing result
3232
* **`0.3.2`**
33-
* make jsonpath inst cloneable.
33+
* make jsonpath inst cloneable.
3434
* **`0.3.3`**
35-
* fix a bug with the logical operators
35+
* fix a bug with the logical operators
3636
* **`0.3.4`**
37-
* add a result as a path
37+
* add a result as a path
3838
* **`0.3.5`**
39-
* add `!` negation operation in filters
40-
* allow using () in filters
39+
* add `!` negation operation in filters
40+
* allow using () in filters
4141
* **`0.5`**
42-
* add config for jsonpath
43-
* add an option to add a regex cache for boosting performance
42+
* add config for jsonpath
43+
* add an option to add a regex cache for boosting performance
44+
* **`0.5.1`**
45+
* add double quotes for the expressions (before it was only possible to use single quotes)
46+
* add Debug on the JsonPathFinder
4447

4548

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "jsonpath-rust"
33
description = "The library provides the basic functionality to find the set of the data according to the filtering query."
4-
version = "0.5.0"
4+
version = "0.5.1"
55
authors = ["BorisZhguchev <[email protected]>"]
66
edition = "2018"
77
license-file = "LICENSE"

src/lib.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ use crate::path::config::JsonPathConfig;
120120
use crate::path::{json_path_instance, PathInstance};
121121
use serde_json::Value;
122122
use std::convert::TryInto;
123-
use std::fmt::Debug;
123+
use std::fmt;
124+
use std::fmt::{Debug, Formatter};
124125
use std::ops::Deref;
125126
use std::str::FromStr;
126127
use JsonPathValue::{NewValue, NoValue, Slice};
@@ -167,7 +168,7 @@ pub trait JsonPathQuery {
167168
fn path(self, query: &str) -> Result<Value, String>;
168169
}
169170

170-
#[derive(Clone)]
171+
#[derive(Clone, Debug)]
171172
pub struct JsonPathInst {
172173
inner: JsonPath,
173174
}
@@ -430,6 +431,17 @@ pub struct JsonPathFinder {
430431
cfg: JsonPathConfig,
431432
}
432433

434+
impl Debug for JsonPathFinder {
435+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
436+
let json_as_str = serde_json::to_string(&*self.json).map_err(|_| fmt::Error)?;
437+
438+
f.write_str("JsonPathFinder:")?;
439+
f.write_str(format!(" json:{}", json_as_str).as_str())?;
440+
f.write_str(format!(" path:{:?}", self.path).as_str())?;
441+
Ok(())
442+
}
443+
}
444+
433445
impl JsonPathFinder {
434446
/// creates a new instance of [JsonPathFinder]
435447
pub fn new(json: Box<Value>, path: Box<JsonPathInst>) -> Self {
@@ -1191,7 +1203,7 @@ mod tests {
11911203
let json: Box<Value> =
11921204
Box::new(json!([{"verb": "TEST"},{"verb": "TEST"}, {"verb": "RUN"}]));
11931205
let path: Box<JsonPathInst> = Box::from(
1194-
JsonPathInst::from_str("$.[?(@.verb == 'RUN1')]").expect("the path is correct"),
1206+
JsonPathInst::from_str("$.[?(@.verb == \"RUN1\")]").expect("the path is correct"),
11951207
);
11961208
let finder = JsonPathFinder::new(json, path);
11971209

src/parser/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use thiserror::Error;
44
use super::parser::Rule;
55

66
#[derive(Error, Debug)]
7+
#[allow(clippy::large_enum_variant)]
78
pub enum JsonPathParserError<'a> {
89
#[error("Failed to parse rule: {0}")]
910
PestError(#[from] pest::error::Error<Rule>),

src/parser/grammar/json_path.pest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ word = _{ ('a'..'z' | 'A'..'Z')+ }
1010
specs = _{ "_" | "-" | "/" | "\\" | "#" }
1111
number = @{"-"? ~ ("0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*) ~ ("." ~ ASCII_DIGIT+)? ~ (^"e" ~ ("+" | "-")? ~ ASCII_DIGIT+)?}
1212

13-
string_qt = ${ "\'" ~ inner ~ "\'" }
13+
string_qt = ${ ("\'" ~ inner ~ "\'") | ("\"" ~ inner ~ "\"") }
1414
inner = @{ char* }
1515
char = _{
1616
!("\"" | "\\" | "\'") ~ ANY

src/parser/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,13 @@ mod tests {
365365
test_failed("[]");
366366
test("[-1,-2]", vec![path!(idx!(idx - 1, -2))]);
367367
test_failed("[abc,bcd]");
368-
test_failed("[\"abc\",\"bcd\"]");
368+
test("[\"abc\",\"bcd\"]", vec![path!(idx!("abc", "bcd"))]);
369369
}
370370

371371
#[test]
372372
fn array_start_test() {
373373
test(
374-
"$.[?(@.verb== 'TEST')]",
374+
"$.[?(@.verb== \"TEST\")]",
375375
vec![
376376
path!($),
377377
path!(idx!(?filter!(op!(chain!(path!(@,path!("verb")))),"==",op!("TEST")))),

0 commit comments

Comments
 (0)