it IS A BUG!!!! find is not the same as match!!!!

2 views
Skip to first unread message

deanhiller

unread,
Jul 13, 2008, 9:14:28 PM7/13/08
to UrlRewrite
In the documentation it has the following code which is NOT how they
do it in URLRewriter. They use find not match and this just about
killed me. Here is code proving find and match are different....

String pat = "^/([a-zA-Z]*)(\\?.*)?";
Pattern pattern1 = Pattern.compile(pat, Pattern.CASE_INSENSITIVE);

String url = "/web/home.xhtml";
Matcher matcher = pattern1.matcher(url);

boolean matches = matcher.matches();

matcher.reset();

//if not found return..
boolean wasFound = matcher.find();

notice match returns false as I expect, and find returns true!!!!!

The documentation in URLRewriter has this which is not how they do it
in the code(they use find which IS different...this is a major BUG in
my eyes).....I was not expecting it to match my rule but it did
because it found a match inside my rule. I should be able to define a
rule that if not matched continues on even if there is a section that
does match!!! but I can't because URLRewriter was using fine...at
least in the version of code I have!!!

Pattern.compile(<from> element);
pattern.matcher(each request url);
matcher.replaceAll(<to> element);
if ( <condition> elements match && pattern matched ) {
execute <run> elements (if any)
perform <to> element (if any)
}

Anyways, bottom line....Use find in your unit tests to determine if
your regex is correct..do not use match which is different!!! Can we
get this fixed???

Paul Tuckey

unread,
Jul 13, 2008, 9:42:44 PM7/13/08
to urlre...@googlegroups.com
This is the way it is supposed to work. The psuedo code you are
looking at in the documentation is just that. It is not java code.

Note, javadoc for find:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Matcher.html#find()

If you want your expression to be matches exactly begin it with a $
and end it with a ^. This will force the entire string top be
matched.

eg, String pat = "^/([a-zA-Z]*)(\\?.*)?$";

Cheers,
Paul.

--
Cheers,
Paul.

Reply all
Reply to author
Forward
0 new messages