From 9d1ae748ff4fc6b330baeab4bfe30a0bead7aad2 Mon Sep 17 00:00:00 2001 From: kkondaka <41027584+kkondaka@users.noreply.github.com> Date: Thu, 15 Feb 2024 08:19:57 -0800 Subject: [PATCH] Allow . and @ characters to be part of json pointer in expressions (#4130) Signed-off-by: Krishna Kondaka Co-authored-by: Krishna Kondaka --- data-prepper-expression/src/main/antlr/DataPrepperExpression.g4 | 2 +- .../expression/GenericExpressionEvaluator_ConditionalIT.java | 2 ++ docs/expression_syntax.md | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/data-prepper-expression/src/main/antlr/DataPrepperExpression.g4 b/data-prepper-expression/src/main/antlr/DataPrepperExpression.g4 index e2946cad8f..97b19df91f 100644 --- a/data-prepper-expression/src/main/antlr/DataPrepperExpression.g4 +++ b/data-prepper-expression/src/main/antlr/DataPrepperExpression.g4 @@ -217,7 +217,7 @@ JsonPointerCharacters fragment JsonPointerCharacter - : [A-Za-z0-9_] + : [A-Za-z0-9_.@] ; EscapedJsonPointer diff --git a/data-prepper-expression/src/test/java/org/opensearch/dataprepper/expression/GenericExpressionEvaluator_ConditionalIT.java b/data-prepper-expression/src/test/java/org/opensearch/dataprepper/expression/GenericExpressionEvaluator_ConditionalIT.java index 55ceb338a8..29639bad5e 100644 --- a/data-prepper-expression/src/test/java/org/opensearch/dataprepper/expression/GenericExpressionEvaluator_ConditionalIT.java +++ b/data-prepper-expression/src/test/java/org/opensearch/dataprepper/expression/GenericExpressionEvaluator_ConditionalIT.java @@ -152,6 +152,8 @@ private static Stream validExpressionArguments() { Arguments.of("/status_code == 200", event("{}"), false), Arguments.of("/success == /status_code", event("{\"success\": true, \"status_code\": 200}"), false), Arguments.of("/success != /status_code", event("{\"success\": true, \"status_code\": 200}"), true), + Arguments.of("/part1@part2.part3 != 111", event("{\"success\": true, \"part1@part2.part3\":111, \"status_code\": 200}"), false), + Arguments.of("/part1.part2@part3 != 111", event("{\"success\": true, \"part1.part2@part3\":222, \"status_code\": 200}"), true), Arguments.of("/pi == 3.14159", event("{\"pi\": 3.14159}"), true), Arguments.of("/value == 12345.678", event("{\"value\": 12345.678}"), true), Arguments.of("/value == 12345.678E12", event("{\"value\": 12345.678E12}"), true), diff --git a/docs/expression_syntax.md b/docs/expression_syntax.md index 80191153e1..ad0392d408 100644 --- a/docs/expression_syntax.md +++ b/docs/expression_syntax.md @@ -137,7 +137,7 @@ Hard coded token that identifies the operation use in an _Expression_. ### Json Pointer A Literal used to reference a value within the Event provided as context for the _Expression String_. Json Pointers are identified by a -leading `/` containing alphanumeric character or underscores, delimited by `/`. Json Pointers can use an extended character set if wrapped +leading `/` containing one of more of characters from the set `a-zA-Z0-9_.@` , delimited by `/`. Json Pointers can use an extended character set if wrapped in double quotes (`"`) using the escape character `\`. Note, Json Pointer require `~` and `/` that should be used as part of the path and not a delimiter to be escaped.