pvillard31 commented on code in PR #11031:
URL: https://github.com/apache/nifi/pull/11031#discussion_r2987385610
##########
nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-processors/src/test/java/org/apache/nifi/processors/jolt/TestJoltTransformJSON.java:
##########
@@ -580,6 +581,41 @@ void testInvalidJsonLinesContent() {
runner.assertAllFlowFilesTransferred(JoltTransformJSON.REL_FAILURE);
}
+ @ParameterizedTest
+ @MethodSource("unicodeEscaping")
+ void testWithUnicodeEscaping(boolean resolveUnicodeEscapeSequences, String
expectedText) {
+ final String unicodeJson = """
+ {"value":
"\\u011f\\u00fc\\u015f\\u0131\\u00f6\\u00e7\\u011e\\u00dc\\u015e\\u0130\\u00d6\\u00c7"}""";
+ final String passThroughSpec = """
+ [
+ {
+ "operation": "shift",
+ "spec": {
+ "*": "&"
+ }
+ }
+ ]""";
+
+ runner.setProperty(JoltTransformJSON.JOLT_SPEC, passThroughSpec);
+ runner.setProperty(JoltTransformJSON.RETAIN_UNICODE_ESCAPE_SEQUENCES,
Boolean.toString(resolveUnicodeEscapeSequences));
+ runner.enqueue(unicodeJson);
+ runner.run();
+
+ runner.assertAllFlowFilesTransferred(JoltTransformJSON.REL_SUCCESS);
+ final MockFlowFile transformed =
runner.getFlowFilesForRelationship(JoltTransformJSON.REL_SUCCESS).getFirst();
+ // NOTE: The JSON specification allows for both uppercase and
lowercase hexadecimal letters.
+ // Jackson seems to prefer to upper case them hence must test with
case insensitivity when unicode escape sequence is retained.
+ assertTrue(Strings.CI.contains(transformed.getContent(),
expectedText));
Review Comment:
commons-lang3 is pulled in transitively so I'd recommend to add it with test
scope or just change to:
```suggestion
assertTrue(transformed.getContent().toLowerCase().contains(expectedText.toLowerCase()));
```
##########
nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-processors/src/test/java/org/apache/nifi/processors/jolt/TestJoltTransformJSON.java:
##########
@@ -580,6 +581,41 @@ void testInvalidJsonLinesContent() {
runner.assertAllFlowFilesTransferred(JoltTransformJSON.REL_FAILURE);
}
+ @ParameterizedTest
+ @MethodSource("unicodeEscaping")
+ void testWithUnicodeEscaping(boolean resolveUnicodeEscapeSequences, String
expectedText) {
Review Comment:
For consistency
```suggestion
void testWithUnicodeEscaping(boolean retainUnicodeEscapeSequences,
String expectedText) {
```
##########
nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-processors/src/main/java/org/apache/nifi/processors/jolt/JoltTransformJSON.java:
##########
@@ -112,6 +113,15 @@ public class JoltTransformJSON extends
AbstractJoltTransform {
.addValidator(StandardValidators.DATA_SIZE_VALIDATOR)
.build();
+ public static final PropertyDescriptor RETAIN_UNICODE_ESCAPE_SEQUENCES =
new PropertyDescriptor.Builder()
+ .name("Retain Unicode Escape Sequences")
+ .description("Allows for retaining Unicode escape sequences
instead of resolving them (e.g. retain text \u00E9 without resolving to é)")
Review Comment:
I believe you need the below otherwise the description will not show the
difference. Please double check to be sure.
```suggestion
.description("Allows for retaining Unicode escape sequences
instead of resolving them (e.g. retain text \\u00E9 without resolving to é)")
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]