This is an automated email from the ASF dual-hosted git repository.
bamaer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new 3e39835109 Align Timestamp and Internet address trimming, fixes #9255
(#9258)
3e39835109 is described below
commit 3e3983510963eeab83d99ff6d3443e08e5f8208c
Author: Hans Van Akelyen <[email protected]>
AuthorDate: Wed Nov 4 17:33:27 2026 +0100
Align Timestamp and Internet address trimming, fixes #9255 (#9258)
---
.../core/row/value/ValueMetaInternetAddress.java | 34 +----------
.../hop/core/row/value/ValueMetaTimestamp.java | 33 +----------
.../row/value/ValueMetaTrimConsistencyTest.java | 67 ++++++++++++++++++++++
3 files changed, 71 insertions(+), 63 deletions(-)
diff --git
a/core/src/main/java/org/apache/hop/core/row/value/ValueMetaInternetAddress.java
b/core/src/main/java/org/apache/hop/core/row/value/ValueMetaInternetAddress.java
index eadd37ea71..a18acf87ab 100644
---
a/core/src/main/java/org/apache/hop/core/row/value/ValueMetaInternetAddress.java
+++
b/core/src/main/java/org/apache/hop/core/row/value/ValueMetaInternetAddress.java
@@ -370,38 +370,8 @@ public class ValueMetaInternetAddress extends
ValueMetaDate {
}
}
- StringBuilder strpol;
- // Trimming
- switch (trimType) {
- case IValueMeta.TRIM_TYPE_LEFT:
- strpol = new StringBuilder(pol);
- while (!strpol.isEmpty() && strpol.charAt(0) == ' ') {
- strpol.deleteCharAt(0);
- }
- pol = strpol.toString();
-
- break;
- case IValueMeta.TRIM_TYPE_RIGHT:
- strpol = new StringBuilder(pol);
- while (!strpol.isEmpty() && strpol.charAt(strpol.length() - 1) == ' ')
{
- strpol.deleteCharAt(strpol.length() - 1);
- }
- pol = strpol.toString();
-
- break;
- case IValueMeta.TRIM_TYPE_BOTH:
- strpol = new StringBuilder(pol);
- while (!strpol.isEmpty() && strpol.charAt(0) == ' ') {
- strpol.deleteCharAt(0);
- }
- while (!strpol.isEmpty() && strpol.charAt(strpol.length() - 1) == ' ')
{
- strpol.deleteCharAt(strpol.length() - 1);
- }
- pol = strpol.toString();
- break;
- default:
- break;
- }
+ // Trim the same way as every other value type (Unicode whitespace,
non-breaking space)
+ pol = Const.trimToType(pol, trimType);
// On with the regular program...
// Simply call the ValueMeta routines to do the conversion
diff --git
a/core/src/main/java/org/apache/hop/core/row/value/ValueMetaTimestamp.java
b/core/src/main/java/org/apache/hop/core/row/value/ValueMetaTimestamp.java
index bd5f556d9b..a885055e03 100644
--- a/core/src/main/java/org/apache/hop/core/row/value/ValueMetaTimestamp.java
+++ b/core/src/main/java/org/apache/hop/core/row/value/ValueMetaTimestamp.java
@@ -334,37 +334,8 @@ public class ValueMetaTimestamp extends ValueMetaDate {
}
}
- // Trimming
- StringBuilder strpol;
- switch (trimType) {
- case IValueMeta.TRIM_TYPE_LEFT:
- strpol = new StringBuilder(pol);
- while (!strpol.isEmpty() && strpol.charAt(0) == ' ') {
- strpol.deleteCharAt(0);
- }
- pol = strpol.toString();
-
- break;
- case IValueMeta.TRIM_TYPE_RIGHT:
- strpol = new StringBuilder(pol);
- while (!strpol.isEmpty() && strpol.charAt(strpol.length() - 1) == ' ')
{
- strpol.deleteCharAt(strpol.length() - 1);
- }
- pol = strpol.toString();
- break;
- case IValueMeta.TRIM_TYPE_BOTH:
- strpol = new StringBuilder(pol);
- while (!strpol.isEmpty() && strpol.charAt(0) == ' ') {
- strpol.deleteCharAt(0);
- }
- while (!strpol.isEmpty() && strpol.charAt(strpol.length() - 1) == ' ')
{
- strpol.deleteCharAt(strpol.length() - 1);
- }
- pol = strpol.toString();
- break;
- default:
- break;
- }
+ // Trim the same way as every other value type (Unicode whitespace,
non-breaking space)
+ pol = Const.trimToType(pol, trimType);
// On with the regular program...
// Simply call the ValueMeta routines to do the conversion
diff --git
a/core/src/test/java/org/apache/hop/core/row/value/ValueMetaTrimConsistencyTest.java
b/core/src/test/java/org/apache/hop/core/row/value/ValueMetaTrimConsistencyTest.java
new file mode 100644
index 0000000000..a7ebbc8950
--- /dev/null
+++
b/core/src/test/java/org/apache/hop/core/row/value/ValueMetaTrimConsistencyTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+package org.apache.hop.core.row.value;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.net.InetAddress;
+import java.sql.Timestamp;
+import org.apache.hop.core.row.IValueMeta;
+import org.junit.jupiter.api.Test;
+
+/** Timestamp and Internet address fields trim like every other value type.
Issue #9255. */
+class ValueMetaTrimConsistencyTest {
+
+ private static final String PADDING_START = "\t ";
+ private static final String PADDING_END = " \t";
+
+ @Test
+ void timestampTrimsTabsAndNonBreakingSpaces() throws Exception {
+ ValueMetaTimestamp timestamp = new ValueMetaTimestamp("ts");
+ String text = "2024/05/17 10:00:00.123456789";
+
+ Object value =
+ timestamp.convertDataFromString(
+ PADDING_START + text + PADDING_END,
+ new ValueMetaString("s"),
+ null,
+ null,
+ IValueMeta.TRIM_TYPE_BOTH);
+
+ assertEquals(
+ timestamp.convertDataFromString(
+ text, new ValueMetaString("s"), null, null,
IValueMeta.TRIM_TYPE_NONE),
+ value);
+ assertEquals(123456789, ((Timestamp) value).getNanos());
+ }
+
+ @Test
+ void internetAddressTrimsTabsAndNonBreakingSpaces() throws Exception {
+ ValueMetaInternetAddress address = new ValueMetaInternetAddress("ip");
+
+ Object value =
+ address.convertDataFromString(
+ PADDING_START + "127.0.0.1" + PADDING_END,
+ new ValueMetaString("s"),
+ null,
+ null,
+ IValueMeta.TRIM_TYPE_BOTH);
+
+ assertEquals(InetAddress.getByName("127.0.0.1"), value);
+ }
+}