mirror of https://github.com/apache/nifi.git
NIFI-13890 Fixed referencing components for quoted parameter names (#9411)
Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
parent
811af23343
commit
56f859f37f
|
@ -45,7 +45,19 @@ public abstract class AbstractParameterParser implements ParameterParser {
|
|||
final ParameterToken token;
|
||||
if (sequentialStartTags % 2 == 1) {
|
||||
final String parameterName = input.substring(startCharIndex + sequentialStartTags + 1, endCharIndex);
|
||||
token = new StandardParameterReference(parameterName, startOffset, endCharIndex, referenceText);
|
||||
if (parameterName.contains("'")) {
|
||||
if (parameterName.startsWith("'") && parameterName.endsWith("'")) {
|
||||
final String parameterNameWithoutQuotes = parameterName.substring(1, parameterName.length() - 1);
|
||||
if (parameterNameWithoutQuotes.contains("'")) {
|
||||
return null;
|
||||
}
|
||||
token = new StandardParameterReference(parameterNameWithoutQuotes, startOffset, endCharIndex, referenceText);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
token = new StandardParameterReference(parameterName, startOffset, endCharIndex, referenceText);
|
||||
}
|
||||
} else {
|
||||
token = new EscapedParameterReference(startOffset, endCharIndex, referenceText);
|
||||
}
|
||||
|
|
|
@ -164,8 +164,10 @@ public class TestExpressionLanguageAgnosticParameterParser {
|
|||
@Test
|
||||
public void testNonReferences() {
|
||||
final ParameterParser parameterParser = new ExpressionLanguageAgnosticParameterParser();
|
||||
final String[] badReferences = new String[] {"#foo", "Some text #{blah foo", "#foo}", "#}foo{",
|
||||
"#{'fo'o}", "#{'My'Param'}", "#f{oo}", "#", "##", "###", "####", "#####", "#{", "##{", "###{"};
|
||||
|
||||
for (final String input : new String[] {"#foo", "Some text #{blah foo", "#foo}", "#}foo{", "#f{oo}", "#", "##", "###", "####", "#####", "#{", "##{", "###{"}) {
|
||||
for (final String input : badReferences) {
|
||||
assertEquals(0, parameterParser.parseTokens(input).toList().size());
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +182,7 @@ public class TestExpressionLanguageAgnosticParameterParser {
|
|||
@Test
|
||||
public void testReferenceInsideAndOutsideExpressionLanguage() {
|
||||
final ParameterParser parameterParser = new ExpressionLanguageAgnosticParameterParser();
|
||||
final List<ParameterToken> tokens = parameterParser.parseTokens("#{hello}${#{hello}:toUpper()}#{hello}").toList();
|
||||
final List<ParameterToken> tokens = parameterParser.parseTokens("#{hello}${#{'hello'}:toUpper()}#{hello}").toList();
|
||||
assertEquals(3, tokens.size());
|
||||
|
||||
for (final ParameterToken token : tokens) {
|
||||
|
@ -206,12 +208,12 @@ public class TestExpressionLanguageAgnosticParameterParser {
|
|||
@Test
|
||||
public void testMultipleReferencesSameExpression() {
|
||||
final ParameterParser parameterParser = new ExpressionLanguageAgnosticParameterParser();
|
||||
final List<ParameterToken> tokens = parameterParser.parseTokens("${#{hello}:append(#{there})}").toList();
|
||||
final List<ParameterToken> tokens = parameterParser.parseTokens("${#{'my parameter'}:append(#{there})}").toList();
|
||||
assertEquals(2, tokens.size());
|
||||
|
||||
final ParameterToken firstToken = tokens.get(0);
|
||||
assertTrue(firstToken.isParameterReference());
|
||||
assertEquals("hello", ((ParameterReference) firstToken).getParameterName());
|
||||
assertEquals("my parameter", ((ParameterReference) firstToken).getParameterName());
|
||||
|
||||
final ParameterToken secondToken = tokens.get(1);
|
||||
assertTrue(secondToken.isParameterReference());
|
||||
|
|
Loading…
Reference in New Issue