[
https://issues.apache.org/jira/browse/MINIFICPP-330?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16290078#comment-16290078
]
ASF GitHub Bot commented on MINIFICPP-330:
------------------------------------------
Github user phrocker commented on a diff in the pull request:
https://github.com/apache/nifi-minifi-cpp/pull/219#discussion_r156815280
--- Diff:
libminifi/test/expression-language-tests/ExpressionLanguageTests.cpp ---
@@ -235,3 +242,51 @@ TEST_CASE("GetFile PutFile dynamic attribute",
"[expressionLanguageTestGetFilePu
REQUIRE("extracted_attr" == output_str.str());
}
}
+
+TEST_CASE("Substring 2 arg", "[expressionLanguageSubstring2]") { // NOLINT
+ auto expr = expression::compile("text_before${attr:substring(6,
8)}text_after");
+
+ auto flow_file_a = std::make_shared<MockFlowFile>();
+ flow_file_a->addAttribute("attr", "__flow_a_attr_value_a__");
+ REQUIRE("text_before_a_attr_text_after" == expr({flow_file_a}));
+}
+
+TEST_CASE("Substring 1 arg", "[expressionLanguageSubstring1]") { // NOLINT
+ auto expr =
expression::compile("text_before${attr:substring(6)}text_after");
+
+ auto flow_file_a = std::make_shared<MockFlowFile>();
+ flow_file_a->addAttribute("attr", "__flow_a_attr_value_a__");
+ REQUIRE("text_before_a_attr_value_a__text_after" == expr({flow_file_a}));
+}
+
+TEST_CASE("Substring Before", "[expressionLanguageSubstringBefore]") { //
NOLINT
+ auto expr =
expression::compile("${attr:substringBefore('attr_value_a__')}");
--- End diff --
I saw the un-guarded substring calls in expr_substringBefore. I assumed
that calling args[0] is likely not possible since there were no conditionals;
however, what happens if the user enters attr:substrinBefore ? Will they
receive an error that is gracefully handled?
> Implement substring operations in Expression Language
> -----------------------------------------------------
>
> Key: MINIFICPP-330
> URL: https://issues.apache.org/jira/browse/MINIFICPP-330
> Project: NiFi MiNiFi C++
> Issue Type: Improvement
> Reporter: Andrew Christianson
> Assignee: Andrew Christianson
>
> Add support for these substring functions to EL:
> substring
> substringBefore
> substringBeforeLast
> substringAfter
> substringAfterLast
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)