Am 22.09.2014 um 11:13 schrieb Marijn Wijbenga:
I've attached a jmeter project file and a html file that demonstrates the 
issue. In order to reproduce:
1. Load up xml-bug-test.jmx in jmeter.
2. Start the proxy (recorder)
3. Place xml-bug-test.html on a webserver somewhere (if on localhost, do not 
forget to remove localhost from proxy exclusion if applicable)
4. Navigate with a browser to this file (using the proxy)
5. Click both buttons in order.

I could not post to a html file, hence the "test 2" button will post to Google. 
The page that loads has an error, but it still records the post request which is what we 
want to see.

I also discovered that when I was using a "get" request instead (I've made that 
"test 1") then it doesn't match the first character (%). I think this is related.

The project has a user defined variable called "TEST" with a value os ".*", 
I've ticked the box

To see the results, in the recording controller the last two requests contain a 
parameter with these values:
Test 1: %${TEST}
Test 2: <${TEST}>

Both should be just ${TEST} I believe.
In the current implementation the regex will be matched against a pattern which looks like
 \b(YOUR_VALUE)\b

As % and < are boundary characters they are excluded from you pattern.

I would consider this a bug, or at least documentation could be a bit more concise.

Attached is a patch against trunk, which checks the regex if it starts with '(' and ends with ')' and uses the regex as given, instead of building its own version.

Regards
 Felix

Also, see notes below.


-----Original Message-----
From: sebb [mailto:[email protected]]
Sent: 21 September 2014 01:52
To: JMeter Users List
Subject: Re: Test Script Recorder XML Regex Matching

On 19 September 2014 16:45, Marijn Wijbenga
<[email protected]> wrote:
Hi,

I have an issue, which might well be a potential bug, where a posted value is
not being matched by the Test Script Recorder's Regex Matching functionality.
The request I'm recording has a post value containing XML (SAML token to be
exact) which I'd like to replace with a variable automatically.

What does the value look like?
Does it have multiple lines?
No, it did not have multiple lines. I did check if this was the case, but it 
wasn’t

For testing purposes I have configured a User Defined Variable (called TEST)
with a value of "(?s)^.*$", I've tried "^.*$" and ".*" as well (all without 
double
quotes).
Only ".*" replaces the content with this: <${TEST}>
That does not make sense.
".*" will match everything, including < and >, so the content would become
${TEST}
I know. It doesn't really. Hence I think this might be a bug.

I've tried other expressions as well and I'm able to match anything within the
<> characters, but not those characters itself.

Again, that does not make sense.
The weird thing is, that inside the outer <> characters there are other <> 
characters that are matched fine. It's just the first and last character.

Does anyone else have experienced the same thing, or is this a known issue?
It is not a known issue, and may not even be an issue.

Or should I post this in the developer's mailing list?
No, the developers all follow this list.
Great, please see attachment for an example.

Cheers
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

>From 73aedf5f2824768e4912f52acb34c201fcdf0eac Mon Sep 17 00:00:00 2001
From: Felix Schumacher <[email protected]>
Date: Sun, 28 Sep 2014 19:05:38 +0200
Subject: [PATCH] If regex starts with '(' and ends with ')' the user wants to
 include the boundary chars in the matched string.

---
 .../engine/util/ReplaceFunctionsWithStrings.java   | 10 +++++++++-
 .../jmeter/engine/util/TestValueReplacer.java      | 22 +++++++++++++++++++++-
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/src/core/org/apache/jmeter/engine/util/ReplaceFunctionsWithStrings.java b/src/core/org/apache/jmeter/engine/util/ReplaceFunctionsWithStrings.java
index 5a47bfd..e2abffb 100644
--- a/src/core/org/apache/jmeter/engine/util/ReplaceFunctionsWithStrings.java
+++ b/src/core/org/apache/jmeter/engine/util/ReplaceFunctionsWithStrings.java
@@ -79,7 +79,7 @@ public class ReplaceFunctionsWithStrings extends AbstractTransformer {
             String value = entry.getValue();
             if (regexMatch) {
                 try {
-                    pattern = compiler.compile("\\b("+value+")\\b");
+                    pattern = compiler.compile(constructPattern(value));
                     input = Util.substitute(pm, pattern,
                             new StringSubstitution(FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX),
                             input, Util.SUBSTITUTE_ALL);
@@ -92,4 +92,12 @@ public class ReplaceFunctionsWithStrings extends AbstractTransformer {
         }
         return new StringProperty(prop.getName(), input);
     }
+
+    private String constructPattern(String value) {
+        if (value.startsWith("(") && value.endsWith(")")) {
+            return value;
+        }
+	return "\\b(" + value + ")\\b";
+    }
+
 }
diff --git a/test/src/org/apache/jmeter/engine/util/TestValueReplacer.java b/test/src/org/apache/jmeter/engine/util/TestValueReplacer.java
index 8e47786..d092c7c 100644
--- a/test/src/org/apache/jmeter/engine/util/TestValueReplacer.java
+++ b/test/src/org/apache/jmeter/engine/util/TestValueReplacer.java
@@ -47,7 +47,8 @@ public class TestValueReplacer extends JMeterTestCase {
             // The following used to be jacks_password, but the Arguments class uses
             // HashMap for which the order is not defined.
             variables.addParameter("password", "his_password");
-            variables.addParameter("regex", ".*");
+            variables.addParameter("normal_regex", "Hello .*");
+            variables.addParameter("bounded_regex", "(<.*>)");
             JMeterVariables vars = new JMeterVariables();
             vars.put("server", "jakarta.apache.org");
             JMeterContextService.getContext().setVariables(vars);
@@ -72,6 +73,25 @@ public class TestValueReplacer extends JMeterTestCase {
             assertEquals("${password}", args.get(1).getStringValue());
         }
 
+        public void testReverseReplacementXml() throws Exception {
+            ValueReplacer replacer = new ValueReplacer(variables);
+            assertTrue(variables.getUserDefinedVariables().containsKey("bounded_regex"));
+            assertTrue(variables.getUserDefinedVariables().containsKey("normal_regex"));
+            assertTrue(replacer.containsKey("bounded_regex"));
+            assertTrue(replacer.containsKey("normal_regex"));
+            TestElement element = new TestPlan();
+            element.setProperty(new StringProperty("domain", "<this><is>xml</this></is>"));
+            List<Object> argsin = new ArrayList<Object>();
+            argsin.add("<this><is>xml</this></is>");
+            argsin.add("And I say: Hello World.");
+            element.setProperty(new CollectionProperty("args", argsin));
+            replacer.reverseReplace(element, true);
+            @SuppressWarnings("unchecked")
+            List<JMeterProperty> args = (List<JMeterProperty>) element.getProperty("args").getObjectValue();
+            assertEquals("${bounded_regex}", element.getPropertyAsString("domain"));
+            assertEquals("${bounded_regex}", args.get(0).getStringValue());
+        }
+
         public void testReplace() throws Exception {
             ValueReplacer replacer = new ValueReplacer();
             replacer.setUserDefinedVariables(variables.getUserDefinedVariables());
-- 
1.9.1


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to