@@ -19,10 +19,10 @@ get_obj_by_key = lambda obj: any, key: str -> any {
19
19
ty = typeof(obj)
20
20
# Schema
21
21
if ty not in KCL_BUILTIN_TYPES:
22
- result = obj[key]
22
+ result = obj[_rfc6901Decode( key) ]
23
23
# Config
24
24
elif ty == "dict":
25
- result = obj[key]
25
+ result = obj[_rfc6901Decode( key) ]
26
26
# List
27
27
elif ty == "list":
28
28
idx = _get_list_index_from_key(key)
@@ -51,6 +51,12 @@ _get_obj_n = lambda obj: any, elements: [str], n: int -> any {
51
51
result
52
52
}
53
53
54
+ # From http://tools.ietf.org/html/rfc6901#section-4 :
55
+ # Transforming '~1' to '/', and then '~0' to '~'.
56
+ _rfc6901Decode = lambda string: str {
57
+ result = string.replace("~1","/").replace("~0","~")
58
+ }
59
+
54
60
_build_patch_obj_n = lambda obj: {str:}, value: any, elements: [str], n: int -> {str:} {
55
61
assert n >= 0
56
62
result = Undefined
@@ -66,18 +72,18 @@ _build_patch_obj_n = lambda obj: {str:}, value: any, elements: [str], n: int ->
66
72
idx = next_key
67
73
assert 0 <= idx < len(current_obj), "value not found for path: {}".format(current_path + "/" + elements[n + 1])
68
74
result = {
69
- "${elements[n]}": [None] * idx + [next_val] + [None] * (len(current_obj) - 1 - idx)
75
+ "${_rfc6901Decode( elements[n]) }": [None] * idx + [next_val] + [None] * (len(current_obj) - 1 - idx)
70
76
}
71
77
# Config key
72
78
else:
73
79
next_val = _build_patch_obj_n(obj, value, elements, n + 1)
74
80
result = {
75
- "${elements[n]}": next_val
81
+ "${_rfc6901Decode( elements[n]) }": next_val
76
82
}
77
83
# No Next value
78
84
else:
79
85
result = {
80
- "${elements[n]}" = value
86
+ "${_rfc6901Decode( elements[n]) }" = value
81
87
}
82
88
result
83
89
}
0 commit comments