You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ex...@apache.org on 2021/03/25 20:41:18 UTC
[nifi] branch main updated: NIFI-7172 Trim trailing whitespace from
NiFi properties
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.git
The following commit(s) were added to refs/heads/main by this push:
new bff3e94 NIFI-7172 Trim trailing whitespace from NiFi properties
bff3e94 is described below
commit bff3e94c01bc7afbed46fce892a2ab8d14130205
Author: Eric Olson <ea...@yahoo.com>
AuthorDate: Sat Feb 27 11:23:26 2021 -0600
NIFI-7172 Trim trailing whitespace from NiFi properties
This closes #4854
Signed-off-by: David Handermann <ex...@apache.org>
---
.../nifi/properties/NiFiPropertiesLoader.java | 8 ++++++++
.../StandardNiFiPropertiesGroovyTest.groovy | 19 +++++++++++++++++
.../resources/conf/nifi_with_whitespace.properties | 24 ++++++++++++++++++++++
3 files changed, 51 insertions(+)
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/main/java/org/apache/nifi/properties/NiFiPropertiesLoader.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/main/java/org/apache/nifi/properties/NiFiPropertiesLoader.java
index a0feca6..7b01ec3 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/main/java/org/apache/nifi/properties/NiFiPropertiesLoader.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/main/java/org/apache/nifi/properties/NiFiPropertiesLoader.java
@@ -24,7 +24,9 @@ import java.io.InputStream;
import java.security.NoSuchAlgorithmException;
import java.security.Security;
import java.util.Properties;
+import java.util.Set;
import javax.crypto.Cipher;
+import org.apache.commons.lang3.StringUtils;
import org.apache.nifi.security.kms.CryptoUtils;
import org.apache.nifi.util.NiFiProperties;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
@@ -174,6 +176,12 @@ public class NiFiPropertiesLoader {
rawProperties.load(inStream);
logger.info("Loaded {} properties from {}", rawProperties.size(), file.getAbsolutePath());
+ Set<String> keys = rawProperties.stringPropertyNames();
+ for (final String key : keys) {
+ String prop = rawProperties.getProperty(key);
+ rawProperties.setProperty(key, StringUtils.stripEnd(prop, null));
+ }
+
ProtectedNiFiProperties protectedNiFiProperties = new ProtectedNiFiProperties(rawProperties);
return protectedNiFiProperties;
} catch (final Exception ex) {
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/test/groovy/org/apache/nifi/properties/StandardNiFiPropertiesGroovyTest.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/test/groovy/org/apache/nifi/properties/StandardNiFiPropertiesGroovyTest.groovy
index c02dc01..b73ac42 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/test/groovy/org/apache/nifi/properties/StandardNiFiPropertiesGroovyTest.groovy
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/test/groovy/org/apache/nifi/properties/StandardNiFiPropertiesGroovyTest.groovy
@@ -1007,4 +1007,23 @@ class StandardNiFiPropertiesGroovyTest extends GroovyTestCase {
// Assert
assert webMaxContentSize == ""
}
+
+
+ @Test
+ void testShouldStripWhitespace() throws Exception {
+ // Arrange
+ File unprotectedFile = new File("src/test/resources/conf/nifi_with_whitespace.properties")
+ NiFiPropertiesLoader niFiPropertiesLoader = new NiFiPropertiesLoader()
+
+ // Act
+ NiFiProperties niFiProperties = niFiPropertiesLoader.load(unprotectedFile.path)
+
+ // Assert
+ assert niFiProperties.getProperty("nifi.whitespace.propWithNoSpace") == "foo"
+ assert niFiProperties.getProperty("nifi.whitespace.propWithLeadingSpace") == "foo"
+ assert niFiProperties.getProperty("nifi.whitespace.propWithTrailingSpace") == "foo"
+ assert niFiProperties.getProperty("nifi.whitespace.propWithLeadingAndTrailingSpace") == "foo"
+ assert niFiProperties.getProperty("nifi.whitespace.propWithTrailingTab") == "foo"
+ assert niFiProperties.getProperty("nifi.whitespace.propWithMultipleLines") == "foobarbaz"
+ }
}
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/test/resources/conf/nifi_with_whitespace.properties b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/test/resources/conf/nifi_with_whitespace.properties
new file mode 100644
index 0000000..420752e
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/test/resources/conf/nifi_with_whitespace.properties
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# properties with whitespace
+nifi.whitespace.propWithNoSpace=foo
+nifi.whitespace.propWithLeadingSpace= foo
+nifi.whitespace.propWithTrailingSpace=foo
+nifi.whitespace.propWithLeadingAndTrailingSpace= foo
+nifi.whitespace.propWithTrailingTab=foo\t
+nifi.whitespace.propWithMultipleLines=foo\
+ bar\
+ baz