ericdai / pwm

Automatically exported from code.google.com/p/pwm
0 stars 0 forks source link

SMS success regex fails to match multi-line response #132

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Configure SMS Gateway that responds with multi-line success code
2. Configure regex to correctly match success
3. Match fails due to multi line respons

The gateway's response consists of these 2(!) lines:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><S:Body 
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><as:SendSMSResponse 
xmlns:as="http://xxx.xxxxxx.xx/AS-SMSService_1_0/"><result>OK</result></as:SendS
MSResponse></S:Body></soapenv:Envelope>

I would expect the regex .*OK.* to match the above response.

What is the expected output? What do you see instead?
I expect to get a success on sending SMS's and receive only 1 SMS, instead the 
SMS's are retried multiple until the queue is cleaned (time-out).

What version of PWM are you using?
svn 269

A temporary work-around is to not match the gateway's result message.

The fix is simple: make the regex match dot as newline (Dot matches line 
terminator [DOTALL], s flag). As can be tested on this page:

http://www.regexplanet.com/simple/index.html

Original issue reported on code.google.com by mrva...@gmail.com on 24 Oct 2011 at 11:25

GoogleCodeExporter commented 8 years ago
PWM uses the Java regular expression engine:

http://download.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html

It's not going to change.  

I believe if you proceed the expression with (?m), you'll enable multi-line 
mode matching which is probably what you want.

Original comment by jrivard on 24 Oct 2011 at 11:34

GoogleCodeExporter commented 8 years ago
I'm all for doing it myself instead of changing the code (I didn't
suggest you change the Regex enging, just the flag to match newline as
dots). I wasn't aware of the ability to set flags myself.

The ?m suggestion however doesn't do the trick I'm afraid:

2011-10-24 13:37:33, ERROR, util.SmsQueueManager, unexpected exception
while processing sms queue: Dangling meta character '?' near index 0
?m.*OK.*
^
java.util.regex.PatternSyntaxException: Dangling meta character '?' near index 0
?m.*OK.*
^
        at java.util.regex.Pattern.error(Pattern.java:1713)
...

Original comment by mrva...@gmail.com on 24 Oct 2011 at 11:40

GoogleCodeExporter commented 8 years ago
(?s).*OK.* does the trick.

I'll post the solution to the mailinglist as well for documentation's sake.

Original comment by mrva...@gmail.com on 24 Oct 2011 at 11:46

GoogleCodeExporter commented 8 years ago
Groovy.  Thanks for following up.  Menno: should this be added as the default 
flag for this setting?  /methinks thats a little confusing, but thats what the 
reporter is suggesting.  Up to you.

Original comment by jrivard on 24 Oct 2011 at 5:37

GoogleCodeExporter commented 8 years ago
Thinking it over, I've made some changes anyway. It turns out that the response 
is evaluated as a single string in the current implementation, against each of 
the configured regexes.

Therefore, I've set the DOTALL option as default now. This can be overruled, by 
using (?-s), if required in any configured regex.

Original comment by menno.pi...@gmail.com on 2 Nov 2011 at 10:05