From 302843b96d39c271c0805b114892449bec6f96a2 Mon Sep 17 00:00:00 2001 From: Norio Akagi Date: Tue, 25 Jun 2024 17:57:21 -0700 Subject: [PATCH] TrimGlobalStep handles unicode characters as Ltrim and Rtrim --- CHANGELOG.asciidoc | 1 + .../process/traversal/step/map/TrimGlobalStep.java | 13 ++++++++++++- .../gremlin/test/features/map/LTrim.feature | 6 +++++- .../gremlin/test/features/map/RTrim.feature | 6 +++++- .../gremlin/test/features/map/Trim.feature | 6 +++++- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 50a30e99b13..5cc26c66306 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -39,6 +39,7 @@ This release also includes changes from <>. * Deprecated `ltrim()` and `rTrim()` in favor of `l_trim()` and `r_trim` in Python. * Fixed bug in `onCreate` for `mergeV()` where use of the `Cardinality` functions was not properly handled. * Fixed multiple concurrent initially requests caused authentication to fail. +* Fixed so that TrimGlobalStep has the same character control handling as Ltrim and Rtrim ==== Bugs diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/TrimGlobalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/TrimGlobalStep.java index 72f2a4123c6..44f7b7aff25 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/TrimGlobalStep.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/TrimGlobalStep.java @@ -49,7 +49,18 @@ protected E map(final Traverser.Admin traverser) { } // we will pass null values to next step - return null == item? null : (E) ((String) item).trim(); + if (null == item) + return null; + + int start = 0; + while (start < ((String) item).length() && Character.isWhitespace(((String) item).charAt(start))) { + start++; + } + int end = ((String) item).length() - 1; + while (end >= start && Character.isWhitespace(((String) item).charAt(end))) { + end--; + } + return (E) ((String) item).substring(start, end + 1); } @Override diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/LTrim.feature b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/LTrim.feature index 4ca49151095..478f6b65fe3 100644 --- a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/LTrim.feature +++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/LTrim.feature @@ -23,7 +23,7 @@ Feature: Step - lTrim() Given the empty graph And the traversal of """ - g.inject(" feature", " one test", null, "", " ").lTrim() + g.inject(" feature", " one test", null, "", " ", " abc", "abc ", " abc ", "  ").lTrim() """ When iterated to list Then the result should be unordered @@ -33,6 +33,10 @@ Feature: Step - lTrim() | null | | str[] | | str[] | + | str[abc] | + | str[abc ] | + | str[abc ] | + | str[] | @GraphComputerVerificationInjectionNotSupported Scenario: g_injectX__feature__X_lTrim diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/RTrim.feature b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/RTrim.feature index 23df32f871a..4398e866cb0 100644 --- a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/RTrim.feature +++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/RTrim.feature @@ -23,7 +23,7 @@ Feature: Step - rTrim() Given the empty graph And the traversal of """ - g.inject("feature ", "one test ", null, "", " ").rTrim() + g.inject("feature ", "one test ", null, "", " ", " abc", "abc ", " abc ", "  ").rTrim() """ When iterated to list Then the result should be unordered @@ -33,6 +33,10 @@ Feature: Step - rTrim() | null | | str[] | | str[] | + | str[ abc] | + | str[abc] | + | str[ abc] | + | str[] | @GraphComputerVerificationInjectionNotSupported Scenario: g_injectX__feature__X_rTrim diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/Trim.feature b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/Trim.feature index feda1856f93..c4ca7fd3704 100644 --- a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/Trim.feature +++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/Trim.feature @@ -23,7 +23,7 @@ Feature: Step - trim() Given the empty graph And the traversal of """ - g.inject(" feature ", " one test ", null, "", " ").trim() + g.inject(" feature ", " one test ", null, "", " ", " abc", "abc ", " abc ", "  ").trim() """ When iterated to list Then the result should be unordered @@ -33,6 +33,10 @@ Feature: Step - trim() | null | | str[] | | str[] | + | str[abc] | + | str[abc] | + | str[abc] | + | str[] | @GraphComputerVerificationInjectionNotSupported Scenario: g_injectXListXa_bXX_trim