Bug 724467 (BRMS-412) - Problems in the use of escapes in the "matches" operator
Summary: Problems in the use of escapes in the "matches" operator
Keywords:
Status: CLOSED NEXTRELEASE
Alias: BRMS-412
Product: JBoss Enterprise BRMS Platform 5
Classification: JBoss
Component: BRE (Expert, Fusion)
Version: 5.0.2
Hardware: Unspecified
OS: Unspecified
high
unspecified
Target Milestone: ---
: 5.1.0 GA
Assignee: Tihomir Surdilovic
QA Contact:
URL: http://jira.jboss.org/jira/browse/BRM...
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-10-21 17:03 UTC by Alessandro Lazarotti
Modified: 2010-11-23 08:22 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
JBoss Enterprise BRMS Platform 5.0.2, JDK 1.6 (sun/oracle)
Last Closed: 2010-11-23 08:22:45 UTC
Type: Bug


Attachments (Terms of Use)
drools-simple-regex.zip (5.82 KB, application/zip)
2010-10-21 17:31 UTC, Alessandro Lazarotti
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker BRMS-412 0 None None None Never

Description Alessandro Lazarotti 2010-10-21 17:03:25 UTC
Help Desk Ticket Reference: https://c.na7.visual.force.com/apex/Case_View?id=500A00000045vTnIAI&sfdc.override=1
Steps to Reproduce: Use the java code from Drools Project provided by JBossTools or JBDS.
The rule:

//this regex search for 2 letters + 3 numbers + 2 letters, like: "ab123cd"
rule "Regex-A"
	when
		$message: Message(message matches "\w\w\d{3}\w\w")
	then
		System.out.println( "Regex-A working" );
	end

//this regex search for 2 letters + 3 numbers + 2 letters, like: "ab123cd"
rule "Regex-B"
	when
		$message: Message(message matches "\\w\\w\\d{3}\\w\\w")
	then
		System.out.println( "Regex-B working" );
	end

//this regex search for 2 letters + 3 numbers + 2 letters, like: "ab123cd"
rule "Regex-C"
	when
		$message: Message(message.toString matches "\w\w\d{3}\w\w")
	then
		System.out.println( "Regex-C working" );
	end

Only Regex-C and Regex-B works.
Workaround Description: Use escapes like:
Cheese( type matches "(Buffalo)?\\S*Mozarella" )

or toString
Cheese( type.toString matches "(Buffalo)?\\S*Mozarella" )

securitylevel_name: Public

According to official documentation, it is not necessary to use escapes:
"In contrast to Java, escapes are not needed within regular expressions written as string literals." (a note in topic 4.8.2.1.5.)

But it is not true. Actually even the example of the documentation does not work if you do not use escape:

//type is a String
Cheese( type matches "(Buffalo)?\S*Mozarella" )

... should be changed to:

//type is a String
Cheese( type matches "(Buffalo)?\\S*Mozarella" )

Curiously, if you have a attribute of the attribute which matches a regex, you shouldn't use escapes:

//type is "complex type" and value is a String
Cheese( type.value matches "(Buffalo)?\S*Mozarella" )

... it's work!

That said, a workaround to work with simple String attributes, you should use "toString":

//type is "String" 
Cheese( type.toString matches "(Buffalo)?\S*Mozarella")

Comment 1 Alessandro Lazarotti 2010-10-21 17:31:45 UTC
drools-simple-regex.zip is a sample project to simulate that.

Comment 2 Alessandro Lazarotti 2010-10-21 17:31:45 UTC
Attachment: Added: drools-simple-regex.zip


Comment 3 Alessandro Lazarotti 2010-10-21 18:10:43 UTC
Link: Added: This issue is a dependency of JBRULES-2745


Comment 4 Tihomir Surdilovic 2010-10-22 03:39:14 UTC
With this change, using complex types or simple types by default you still have to escape the matching pattern, for example:

when
$task : BinTask( $bn : bin.name matches "\\w\\w\\d{3}\\w\\w" )
$bin : Bin( $nm : name matches "\\w\\w\\d{3}\\w\\w" )
then
...

If you set the drools.parser.processStringEscapes option:
KnowledgeBuilderConfiguration kbconf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
kbconf.setProperty("drools.parser.processStringEscapes", "false");

KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(kbconf);

...

the matches patterns do not have to be escaped, and the patterns can be:

when
$task : BinTask( $bn : bin.name matches "\w\w\d{3}\w\w" )
$bin : Bin( $nm : name matches "\w\w\d{3}\w\w" )
then
... 

Comment 5 David Le Sage 2010-10-25 23:34:51 UTC
Draft text for release notes states:

https://jira.jboss.org/browse/BRMS-412

There was a problem with the use of escapes when using the "matches"operator.  The drools.parser.processStringEscapesoption has been added.  Use of this feature means that matched patterns do not have to be escaped.  

Comment 6 Dana Mison 2010-10-26 06:55:49 UTC
Writer: Added: dlesage


Comment 7 Dana Mison 2010-10-26 07:10:32 UTC
Release Notes Docs Status: Added: Documented as Resolved Issue


Comment 8 Dana Mison 2010-10-27 03:05:51 UTC
Release Notes Text: Added: test


Comment 9 Dana Mison 2010-10-27 03:13:03 UTC
Release Notes Text: Removed: test 


Comment 10 Dana Mison 2010-10-28 02:04:01 UTC
Release Notes Text: Added: There was a problem with the use of escapes when using the "matches"operator. The drools.parser.processStringEscapesoption has been added. Use of this feature means that matched patterns do not have to be escaped. 


Comment 11 Tihomir Surdilovic 2010-10-28 03:32:16 UTC
David, you have to set the drools.parser.processStringEscapes property to false in order for escapes not to be needed.


Note You need to log in before you can comment on or make changes to this bug.