Several years ago, I specialized in Delphi software development.

Amongst several other endeavors, I wrote and sold a Regular Expression matcher. Well, it turns out that my matcher has a significant bug that was only just noticed by a user - handling of “$” to require a match to finish at the end of the line was broken.

Yikes!

For future reference of anyone consulting with Professor Google or Doctor Bing, here’s the fix.

The code inside TniRegularExpressionMatcher.MatchExpression is missing a check for mfFinishOnly.

Inside the repeat loop:

if oState.Accept then begin
  MatchFound(...);
  Result := true;
  if not bContinue then
    break;
end;

This code needs to check for mfFinishOnly as follows:

if oState.Accept then begin
  if not (mfFinishOnly in FxFlags)
     or (iScan=Length(aString)) then
  begin
    MatchFound(...);
    Result := true;
    if not bContinue then
      break;
  end;
end;

In english: If mfFinishOnly is not specified, any match is acceptable; if we’re at the end of the string, the match is always acceptable.

Comments

blog comments powered by Disqus
Next Post
On Priorities  17 Dec 2009
Prior Post
Sequence diagrams in Visual Studio 2010  23 Nov 2009
Related Posts
Contract for Online Access  10 Jan 2014
A story about Magic  10 Dec 2011
Windows Phone 7 vs Z88  27 Sep 2011
Lessons learnt at TechEd  06 Sep 2011
StackOverflow and Clay Shirky  03 Dec 2010
Thanks to the Palmy .NET User Group  16 Nov 2010
Gadget Envy  15 May 2010
Google's new Language  13 Nov 2009
TechEd New Zealand 2009  19 Sep 2009
An Architects Life  26 Aug 2009
More random posts »
Archives
December 2009
2009