File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -261,7 +261,12 @@ def get_context_value(
261261 context : EvaluationContext ,
262262 property : str ,
263263) -> ContextValue :
264- return _get_context_value_getter (property )(context )
264+ if property .startswith ("$." ):
265+ return _get_context_value_getter (property )(context )
266+ if identity_context := context .get ("identity" ):
267+ if traits := identity_context .get ("traits" ):
268+ return traits .get (property )
269+ return None
265270
266271
267272def _matches_context_value (
@@ -385,6 +390,8 @@ def _get_context_value_getter(
385390 try :
386391 compiled_query = jsonpath_rfc9535 .compile (property )
387392 except jsonpath_rfc9535 .JSONPathSyntaxError :
393+ # This covers a rare case when a trait starting with "$.",
394+ # but not a valid JSONPath, is used.
388395 compiled_query = jsonpath_rfc9535 .compile (
389396 f'$.identity.traits["{ escape_double_quotes (property )} "]' ,
390397 )
Original file line number Diff line number Diff line change @@ -1048,3 +1048,19 @@ def test_get_context_value__invalid_jsonpath__returns_expected(
10481048
10491049 # Then
10501050 assert result is None
1051+
1052+
1053+ def test_get_context_value__jsonpath_like_trait__returns_expected (
1054+ context : EvaluationContext ,
1055+ ) -> None :
1056+ # Given
1057+ jsonpath_like_trait = '$. i am not" a valid jsonpath'
1058+ expected_result = "some_value"
1059+ assert context ["identity" ]
1060+ context ["identity" ]["traits" ][jsonpath_like_trait ] = expected_result
1061+
1062+ # When
1063+ result = get_context_value (context , jsonpath_like_trait )
1064+
1065+ # Then
1066+ assert result == expected_result
You can’t perform that action at this time.
0 commit comments