[Bps-public-commit] r15450 - in Path-Dispatcher/trunk: lib/Path/Dispatcher/Dispatch

sartak at bestpractical.com sartak at bestpractical.com
Mon Aug 25 19:34:30 EDT 2008


Author: sartak
Date: Mon Aug 25 19:34:30 2008
New Revision: 15450

Modified:
   Path-Dispatcher/trunk/   (props changed)
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Dispatch/Match.pm

Log:
 r70330 at onn:  sartak | 2008-08-25 19:33:53 -0400
 Eureka. Matching against the empty regex is totally nondeterministic because of older Perl's optimization of //


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Dispatch/Match.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Dispatch/Match.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Dispatch/Match.pm	Mon Aug 25 19:34:30 2008
@@ -52,8 +52,14 @@
     # against a regex (5.10 fixes that)..
     my $re = join '', map { "(\Q$_\E)" } @_;
     my $str = join '', @_;
-    $str =~ $re
-        or die "Unable to match '$str' against a copy of itself!";
+
+    # we need to check length because Perl's annoying gotcha of the empty regex
+    # actually being an alias for whatever the previously used regex was 
+    # (useful last decade when qr// hadn't been invented)
+    if (length($str)) {
+        $str =~ $re
+            or die "Unable to match '$str' against a copy of itself!";
+    }
 
     $code->();
 }



More information about the Bps-public-commit mailing list