Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

for php regex, an escaped char is meta iff the char is alphanumeric

and even though '\\0' in particular has no real use,
it won't match as unmeta:
php> =preg_split('/a\\#/', 'yyya#zzz')
array(
  0 => "yyy",
  1 => "zzz",
)
php> =preg_split('/a#/', 'yyya#zzz')
array(
  0 => "yyy",
  1 => "zzz",
)
php> =preg_split('/a\\0/', 'yyya0zzz')
array(
  0 => "yyya0zzz",
)
php> =preg_split('/a0/', 'yyya0zzz')
array(
  0 => "yyy",
  1 => "zzz",
)

Test Plan:
$bits = preg_split('/[.@]/', $elattr, 2);
$bits = preg_split('/\[\.@]/', $elattr, 2);
$bits = preg_split('/\[\.@\]/', $elattr, 2);
  • Loading branch information...
commit 3f8196eab7a7b400237cc6c4bd0c675ff9bb0643 1 parent 86d1436
@dancor dancor authored
Showing with 8 additions and 3 deletions.
  1. +8 −3 src/Transf/AntiPattern.hs
View
11 src/Transf/AntiPattern.hs
@@ -101,12 +101,17 @@ pregSplitNonRegex = modAll $ \ a -> case a of
else transfNothing
_ -> transfNothing
+regexUnitIsMeta :: [String] -> Bool
regexUnitIsMeta [c] = normedStrUnitIsRegexMeta c
-regexUnitIsMeta ["\\\\", c] = not $ normedStrUnitIsRegexMeta c
+regexUnitIsMeta ["\\\\", c] = isAlphaNum . chr $ phpOrd c
--- e.g. "." and "\x2E" in a PHP str both count as any-char for preg stuff
+-- note that "." and "\x2E" in a PHP str both count as any-char for
+-- preg stuff
normedStrUnitIsRegexMeta :: String -> Bool
-normedStrUnitIsRegexMeta u = any (== phpOrd u) $ map ord "\\|^$*+?.()[{"
+normedStrUnitIsRegexMeta u = any (== chr (phpOrd u)) "\\|^$*+?.()[{"
+
+normedStrUnitIsRegexUnmetaEvenEscaped :: String -> Bool
+normedStrUnitIsRegexUnmetaEvenEscaped u = any (== phpOrd u) $ map ord "]}"
strToArg :: String -> Either Expr b
strToArg = Left . ExprStrLit . StrLit
Please sign in to comment.
Something went wrong with that request. Please try again.