You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2023/05/01 14:59:08 UTC

[jmeter] branch master updated: Trim variable names in Argument objects

This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


The following commit(s) were added to refs/heads/master by this push:
     new c361c4499b Trim variable names in Argument objects
c361c4499b is described below

commit c361c4499be641b5f3e6b30f8c129df857cbefce
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon May 1 15:48:16 2023 +0200

    Trim variable names in Argument objects
    
    Should fix #5872
---
 .../jmeter/config/gui/TestArgumentsPanel.java      | 18 ++++++++++
 .../java/org/apache/jmeter/config/Argument.java    |  5 +--
 .../org/apache/jmeter/config/ArgumentTest.java     | 38 ++++++++++++++++++++++
 xdocs/changes.xml                                  |  1 +
 4 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/src/components/src/test/java/org/apache/jmeter/config/gui/TestArgumentsPanel.java b/src/components/src/test/java/org/apache/jmeter/config/gui/TestArgumentsPanel.java
index 3d25260e59..47d5dd923b 100644
--- a/src/components/src/test/java/org/apache/jmeter/config/gui/TestArgumentsPanel.java
+++ b/src/components/src/test/java/org/apache/jmeter/config/gui/TestArgumentsPanel.java
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertEquals;
 import org.apache.jmeter.config.Argument;
 import org.apache.jmeter.config.Arguments;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
 
 /**
  * A GUI panel allowing the user to enter name-value argument pairs. These
@@ -45,4 +47,20 @@ public class TestArgumentsPanel {
         assertEquals("=", ((Argument) ((Arguments) gui.createTestElement()).getArguments().get(0).getObjectValue())
                 .getMetaData());
     }
+
+
+    @ParameterizedTest
+    @CsvSource(value = {
+            "WITHOUT_SPACE,WITHOUT_SPACE",
+            " WITH_OUTER_SPACE ,WITH_OUTER_SPACE",
+            "WITH_SUFFIX_SPACE ,WITH_SUFFIX_SPACE",
+            " WITH_PREFIX_SPACE,WITH_PREFIX_SPACE"
+    }, ignoreLeadingAndTrailingWhitespace = false)
+    public void testArgumentNames(String name, String expectedName) throws Exception {
+        ArgumentsPanel gui = new ArgumentsPanel();
+        gui.tableModel.addRow(new Argument());
+        gui.tableModel.setValueAt(name, 0, 0);
+
+        assertEquals(expectedName, ((Argument) ((Arguments) gui.createTestElement()).getArguments().get(0).getObjectValue()).getName());
+    }
 }
diff --git a/src/core/src/main/java/org/apache/jmeter/config/Argument.java b/src/core/src/main/java/org/apache/jmeter/config/Argument.java
index 04ca8a2c8d..b97c0fa74e 100644
--- a/src/core/src/main/java/org/apache/jmeter/config/Argument.java
+++ b/src/core/src/main/java/org/apache/jmeter/config/Argument.java
@@ -19,6 +19,7 @@ package org.apache.jmeter.config;
 
 import java.io.Serializable;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.jmeter.testelement.AbstractTestElement;
 import org.apache.jmeter.testelement.property.StringProperty;
 import org.apache.jorphan.util.JOrphanUtils;
@@ -92,7 +93,7 @@ public class Argument extends AbstractTestElement implements Serializable {
      */
     public Argument(String name, String value, String metadata, String description) {
         if(name != null) {
-            setProperty(new StringProperty(ARG_NAME, name));
+            setProperty(new StringProperty(ARG_NAME, StringUtils.strip(name)));
         }
         if(value != null) {
             setProperty(new StringProperty(VALUE, value));
@@ -113,7 +114,7 @@ public class Argument extends AbstractTestElement implements Serializable {
      */
     @Override
     public void setName(String newName) {
-        setProperty(new StringProperty(ARG_NAME, newName));
+        setProperty(new StringProperty(ARG_NAME, StringUtils.strip(newName)));
     }
 
     /**
diff --git a/src/core/src/test/java/org/apache/jmeter/config/ArgumentTest.java b/src/core/src/test/java/org/apache/jmeter/config/ArgumentTest.java
new file mode 100644
index 0000000000..27113227c2
--- /dev/null
+++ b/src/core/src/test/java/org/apache/jmeter/config/ArgumentTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.jmeter.config;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+class ArgumentTest {
+
+    @ParameterizedTest
+    @CsvSource(value = {
+            "simple_name,simple_name",
+            " with_spaces ,with_spaces",
+            "\twith_tabs\t,with_tabs"
+    },ignoreLeadingAndTrailingWhitespace = false)
+    void setName(String name, String expectedName) {
+        Argument arg = new Argument();
+        arg.setName(name);
+        assertEquals(expectedName, arg.getName());
+    }
+}
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 6ad4153dc5..5166ee1759 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -177,6 +177,7 @@ Summary
 <h3>General</h3>
 <ul>
   <li><bug>66157</bug><pr>719</pr>Correct theme for darklaf on rsyntaxtextarea</li>
+  <li><issue>5872</issue><pr>5874</pr>Trim name in Argument objects.</li>
 </ul>
 
  <!--  =================== Thanks =================== -->