File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 11[package ]
22name = " promkit"
3- version = " 0.6.1 "
3+ version = " 0.6.2 "
44authors = [
" ynqa <[email protected] >" ]
55edition = " 2021"
66description = " A toolkit for building your own interactive command-line tools"
Original file line number Diff line number Diff 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+
398408impl < ' 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 }
You can’t perform that action at this time.
0 commit comments