Skip to content

Commit 526d4c4

Browse files
authored
Merge pull request #47 from ynqa/v0.6.2/dev
v0.6.2
2 parents 80ffd5b + 1cae97f commit 526d4c4

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

promkit/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "promkit"
3-
version = "0.6.1"
3+
version = "0.6.2"
44
authors = ["ynqa <[email protected]>"]
55
edition = "2021"
66
description = "A toolkit for building your own interactive command-line tools"

promkit/src/jsonz.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,16 @@ pub struct PathIterator<'a> {
395395
stack: Vec<(String, &'a serde_json::Value)>,
396396
}
397397

398+
impl<'a> PathIterator<'a> {
399+
fn escape_json_path_key(key: &str) -> String {
400+
if key.contains('.') || key.contains('-') || key.contains('@') {
401+
format!("\"{}\"", key)
402+
} else {
403+
key.to_string()
404+
}
405+
}
406+
}
407+
398408
impl<'a> Iterator for PathIterator<'a> {
399409
type Item = String;
400410

@@ -403,10 +413,11 @@ impl<'a> Iterator for PathIterator<'a> {
403413
match value {
404414
serde_json::Value::Object(obj) => {
405415
for (key, val) in obj.iter() {
416+
let escaped = Self::escape_json_path_key(key);
406417
let new_path = if current_path == "." {
407-
format!(".{}", key)
418+
format!(".{}", escaped)
408419
} else {
409-
format!("{}.{}", current_path, key)
420+
format!("{}.{}", current_path, escaped)
410421
};
411422
self.stack.push((new_path, val));
412423
}

0 commit comments

Comments
 (0)