Skip to content

Commit cf11662

Browse files
committed
fix
1 parent a5b2027 commit cf11662

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/common/jsonb/src/functions.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -839,17 +839,15 @@ pub fn parse_json_path(path: &[u8]) -> Result<Vec<JsonPath>, Error> {
839839
}
840840
} else if c == b'"' {
841841
prev_idx = idx;
842-
while idx < path.len() {
842+
loop {
843843
let c = read_char(path, &mut idx)?;
844-
if c != b'"' && c != b'\\' {
844+
if c == b'\\' {
845845
idx += 1;
846-
} else {
847-
// Try to read to check if has extra strings, string value can only have one.
848-
let c = read_char(path, &mut idx);
849-
match c {
850-
Ok(_) => return Err(Error::InvalidToken),
851-
Err(_) => break,
846+
} else if c == b'"' {
847+
if idx < path.len() {
848+
return Err(Error::InvalidToken);
852849
}
850+
break;
853851
}
854852
}
855853
let s = std::str::from_utf8(&path[prev_idx..idx - 1])?;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ fn test_parse_json_path() {
364364
]),
365365
("\"k1\"", vec![JsonPath::String(Cow::from("k1"))]),
366366
("\"k_1\"", vec![JsonPath::String(Cow::from("k_1"))]),
367+
("\"k_1k_2\"", vec![JsonPath::String(Cow::from("k_1k_2"))]),
367368
("\"k1k2\"", vec![JsonPath::String(Cow::from("k1k2"))]),
368369
(r#"k1["k2"][1]"#, vec![
369370
JsonPath::String(Cow::from("k1")),
@@ -380,6 +381,7 @@ fn test_parse_json_path() {
380381
let wrong_sources = vec![
381382
(r#"\"\"\\k1\"\""#, Error::InvalidToken),
382383
(r#"\\k1\\'"#, Error::InvalidToken),
384+
(r#"\"kk\"1\""#, Error::InvalidToken),
383385
];
384386
for (s, expect) in wrong_sources {
385387
let path = parse_json_path(s.as_bytes());

0 commit comments

Comments
 (0)