This is an automated email from the ASF dual-hosted git repository.
exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-api.git
The following commit(s) were added to refs/heads/main by this push:
new 6913182 NIFI-15982 Fixed StandardResourceReferenceFactory
disambiguation for File path and comment prefix (#90)
6913182 is described below
commit 6913182da3ef285aa1f926cb6ec460d9dbf65abc
Author: dan-s1 <[email protected]>
AuthorDate: Tue Jun 2 11:12:06 2026 -0400
NIFI-15982 Fixed StandardResourceReferenceFactory disambiguation for File
path and comment prefix (#90)
Signed-off-by: David Handermann <[email protected]>
---
.../resource/StandardResourceReferenceFactory.java | 14 ++++++++------
.../TestStandardResourceReferenceFactory.java | 20 ++++++++++++++++++++
2 files changed, 28 insertions(+), 6 deletions(-)
diff --git
a/src/main/java/org/apache/nifi/components/resource/StandardResourceReferenceFactory.java
b/src/main/java/org/apache/nifi/components/resource/StandardResourceReferenceFactory.java
index a0a477b..d1aec57 100644
---
a/src/main/java/org/apache/nifi/components/resource/StandardResourceReferenceFactory.java
+++
b/src/main/java/org/apache/nifi/components/resource/StandardResourceReferenceFactory.java
@@ -92,13 +92,15 @@ public class StandardResourceReferenceFactory implements
ResourceReferenceFactor
if (fileAllowed && textAllowed) {
// We have to make a determination whether this is a file or text.
Eventually, it will be best if the user tells us explicitly.
// For now, we will make a determination based on a couple of
simple rules.
- final File file = new File(trimmed);
- if (file.isAbsolute() || file.exists()) {
- return new FileResourceReference(file);
- }
+ if (!trimmed.startsWith("//")) {
+ final File file = new File(trimmed);
+ if (file.isAbsolute() || file.exists()) {
+ return new FileResourceReference(file);
+ }
- if (trimmed.startsWith("./") || trimmed.startsWith(".\\")) {
- return new FileResourceReference(file);
+ if (trimmed.startsWith("./") || trimmed.startsWith(".\\")) {
+ return new FileResourceReference(file);
+ }
}
return new Utf8TextResource(value); // Use explicit value, not
trimmed value, as the white space may be important for textual content.
diff --git
a/src/test/java/org/apache/nifi/components/resource/TestStandardResourceReferenceFactory.java
b/src/test/java/org/apache/nifi/components/resource/TestStandardResourceReferenceFactory.java
index 5a297d9..605ff9a 100644
---
a/src/test/java/org/apache/nifi/components/resource/TestStandardResourceReferenceFactory.java
+++
b/src/test/java/org/apache/nifi/components/resource/TestStandardResourceReferenceFactory.java
@@ -22,8 +22,10 @@ import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.Collections;
import java.util.List;
+import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -67,6 +69,7 @@ public class TestStandardResourceReferenceFactory {
assertEmptyResourceReferences(resourceReferences);
}
+
@Test
public void testCreateResourceReferencesWhenResourceDefinitionIsNull() {
String value = "/dir1/test1.jar";
@@ -77,6 +80,23 @@ public class TestStandardResourceReferenceFactory {
assertEmptyResourceReferences(resourceReferences);
}
+ @Test
+ public void testDisambiguationBetweenTextAndFile() {
+ final String transformWithSingleLineComment = """
+ // This is a single line comment in JSLT
+ {
+ "id": .userId,
+ "name": .firstName
+ }
+ """;
+
+ final ResourceDefinition resourceDefinition =
+ new StandardResourceDefinition(ResourceCardinality.SINGLE,
Set.of(ResourceType.FILE, ResourceType.TEXT));
+ final ResourceReference resourceReference =
subject.createResourceReference(transformWithSingleLineComment,
resourceDefinition);
+
+ assertInstanceOf(Utf8TextResource.class, resourceReference);
+ }
+
private StandardResourceDefinition createResourceDefinition() {
return new StandardResourceDefinition(ResourceCardinality.SINGLE,
Collections.singleton(ResourceType.FILE));
}