Skip to content

Commit f2f6537

Browse files
authored
Merge pull request #9206 from hantmac/fix/parse-double-quote
fix: double-quote in get_path
2 parents 581bf25 + cf11662 commit f2f6537

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/common/jsonb/src/functions.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -843,19 +843,11 @@ pub fn parse_json_path(path: &[u8]) -> Result<Vec<JsonPath>, Error> {
843843
let c = read_char(path, &mut idx)?;
844844
if c == b'\\' {
845845
idx += 1;
846-
let c = read_char(path, &mut idx)?;
847-
if c == b'"' {
848-
idx += 1;
849-
}
850-
} else if c != b'"' {
851-
idx += 1;
852-
} else {
853-
// Try to read to check if has extra strings, string value can only have one.
854-
let c = read_char(path, &mut idx);
855-
match c {
856-
Ok(_) => return Err(Error::InvalidToken),
857-
Err(_) => break,
846+
} else if c == b'"' {
847+
if idx < path.len() {
848+
return Err(Error::InvalidToken);
858849
}
850+
break;
859851
}
860852
}
861853
let s = std::str::from_utf8(&path[prev_idx..idx - 1])?;

src/common/jsonb/tests/it/functions.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ fn test_parse_json_path() {
363363
JsonPath::String(Cow::from("k3")),
364364
]),
365365
("\"k1\"", vec![JsonPath::String(Cow::from("k1"))]),
366+
("\"k_1\"", vec![JsonPath::String(Cow::from("k_1"))]),
367+
("\"k_1k_2\"", vec![JsonPath::String(Cow::from("k_1k_2"))]),
366368
("\"k1k2\"", vec![JsonPath::String(Cow::from("k1k2"))]),
367369
(r#"k1["k2"][1]"#, vec![
368370
JsonPath::String(Cow::from("k1")),
@@ -379,6 +381,7 @@ fn test_parse_json_path() {
379381
let wrong_sources = vec![
380382
(r#"\"\"\\k1\"\""#, Error::InvalidToken),
381383
(r#"\\k1\\'"#, Error::InvalidToken),
384+
(r#"\"kk\"1\""#, Error::InvalidToken),
382385
];
383386
for (s, expect) in wrong_sources {
384387
let path = parse_json_path(s.as_bytes());

0 commit comments

Comments
 (0)