File tree 1 file changed +16
-2
lines changed
1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -227,6 +227,20 @@ fn get_key(data: &Value, key: KeyType) -> Option<Value> {
227
227
}
228
228
}
229
229
230
+ fn split_path ( path : & str ) -> impl Iterator < Item = String > + ' _ {
231
+ let mut index = 0 ;
232
+ return path
233
+ . split ( move |c : char | {
234
+ if c == '.' && path. chars ( ) . nth ( index - 1 ) . unwrap ( ) != '\\' {
235
+ index += 1 ;
236
+ return true ;
237
+ }
238
+ index += 1 ;
239
+ return false ;
240
+ } )
241
+ . map ( |part| part. replace ( "\\ ." , "." ) ) ;
242
+ }
243
+
230
244
fn get_str_key < K : AsRef < str > > ( data : & Value , key : K ) -> Option < Value > {
231
245
let k = key. as_ref ( ) ;
232
246
if k == "" {
@@ -235,9 +249,9 @@ fn get_str_key<K: AsRef<str>>(data: &Value, key: K) -> Option<Value> {
235
249
match data {
236
250
Value :: Object ( _) | Value :: Array ( _) | Value :: String ( _) => {
237
251
// Exterior ref in case we need to make a new value in the match.
238
- k . split ( "." ) . fold ( Some ( data. clone ( ) ) , |acc, i| match acc? {
252
+ split_path ( k ) . fold ( Some ( data. clone ( ) ) , |acc, i| match acc? {
239
253
// If the current value is an object, try to get the value
240
- Value :: Object ( map) => map. get ( i) . map ( Value :: clone) ,
254
+ Value :: Object ( map) => map. get ( & i) . map ( Value :: clone) ,
241
255
// If the current value is an array, we need an integer
242
256
// index. If integer conversion fails, return None.
243
257
Value :: Array ( arr) => i
You can’t perform that action at this time.
0 commit comments