apache / jmeter

Apache JMeter open-source load testing tool for analyzing and measuring the performance of a variety of services
https://jmeter.apache.org/
Apache License 2.0
8.26k stars 2.09k forks source link

Response assertin and regular expressions #1310

Closed asfimport closed 20 years ago

asfimport commented 20 years ago

Petri Suutarinen (Bug 26885): Following string does not work when added to response assertin component.

"<html>.*</html>"

This is copied from the documentation so regular expressions does not work on response assertion component or the documentation is not up to date. I'm using JRE1.4.2_3.

Severity: normal OS: Linux

asfimport commented 20 years ago

Sebb (migrated from Bugzilla): What options are you using on the Response Assertion - are you using "matches" or "contains"?

Perhaps you could right-click and save the RA test element, and post it as an attachment here.

What is the exact text you are matching against? [Please post as an attachment]

There's some further information on Regular Expressions in the JMeter FAQ.

asfimport commented 20 years ago

Petri Suutarinen (migrated from Bugzilla): Created attachment response.html: Response HTML that response assertion can't parse correctly

response.html ````html HTTP/1.1 200 OK Server: Netscape-Enterprise/4.1 Date: Wed, 11 Feb 2004 18:49:00 GMT Cache-control: max-age=1 Set-Cookie: MY_SESSION_ID=116#0DFA879CBEAA401F59E48E9C63247147;Domain=.mydomain.com;Path=/;Max-Age=1200 Expires: Wed, 11 Feb 2004 15:59:00 GMT Content-type: text/html Content-length: 7676 Overzicht weddenschap
 
Trekking: 10 okt
Incl. vri : 10 okt

 
Lot 1      kleur: 
Hercules Xena:
 
Inleg:  &hercules; 2,00
Het deelnemersreglement SNS en de voorwaarden voor internetspellen zijn van toepassing op dit Lot.
````
asfimport commented 20 years ago

Sebb (migrated from Bugzilla): That won't MATCH against

<html>.*</html>

as there is text before the first <html> tag.

However, it should pass a CONTAINS Response Assertion.

If the actual value in the Response Assertion is

"<html>.*</html>"

i.e. with the quotes, neither MATCH nor CONTAINS will succeed.

asfimport commented 20 years ago

Petri Suutarinen (migrated from Bugzilla): I'm using CONTAINS mode. And the string I'm trying to check is really

<html>.*</html>

not with quotes.

asfimport commented 20 years ago

Sebb (migrated from Bugzilla): Sounds as though it should work...

Tried a quick test, and it looks like the response is being treated as multiple lines, and so "." does not match new-line. Sorry, should have realised this earlier...

Try adding (?s) to the start of the line.

asfimport commented 20 years ago

Petri Suutarinen (migrated from Bugzilla): I debugged this problem more deeply and it looks like Perl5Compiler problem. If you look at the JMeter1.9.1 code (line 305). I added there MULTILINE_MASK like this (because there was not one).

        Pattern pattern =
           patternCache.getPattern(
           stringPattern,
             Perl5Compiler.MULTILINE_MASK|Perl5Compiler.READ_ONLY_MASK);

Then I compiled and tried it with a following rexexp: <html>(.|\n)</html>

The result is that contains(..)-function prints java.lang.StackoverflowError. I'm quite poor with regular expressions but I don't think that my example causes infinite loop. I also find discussion about this same problem. Here is link to it.

http://www.mail-archive.com/oro-user@jakarta.apache.org/msg00356.html

Btw. What did you mean with adding (?s) to the start of the line?

asfimport commented 20 years ago

Sebb (migrated from Bugzilla): <html>(.|\n)</html> won't work - you probably meant <html>(.|\n)*</html>

Alternation - i.e. | - is very expensive as the matcher has to be able to backtrack if one of the alternatives does not work.

<html>[.\n]*</html> should work

(?s) means treat as single line, i.e. "." matches "\n"

asfimport commented 20 years ago

Sebb (migrated from Bugzilla): I've updated the component documentation to explain how the matching works, so closing this call