r100139 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100138‎ | r100139 | r100140 >
Date:17:57, 18 October 2011
Author:vasilievvv
Status:resolved (Comments)
Tags:
Comment:
(part of this commit is in r100135 due to SVN fail)
* (bug 24109) Add regex escaping function to abuse filter

Patch by Jérémie Roquet
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.parser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/AbuseFilter.parser.php
@@ -446,6 +446,7 @@
447447 'strlen' => 'funcLen',
448448 'strpos' => 'funcStrPos',
449449 'str_replace' => 'funcStrReplace',
 450+ 'rescape' => 'funcStrRegexEscape',
450451 'set' => 'funcSetVar',
451452 'set_var' => 'funcSetVar',
452453 );
@@ -1742,6 +1743,17 @@
17431744 return new AFPData( AFPData::DString, str_replace( $search, $replace, $subject ) );
17441745 }
17451746
 1747+ protected function funcStrRegexEscape( $args ) {
 1748+ if ( count( $args ) < 1 ) {
 1749+ throw new AFPUserVisibleException( 'notenoughargs', $this->mCur->pos,
 1750+ array( 'rescape', 1, count( $args ) ) );
 1751+ }
 1752+
 1753+ $string = $args[0]->toString();
 1754+
 1755+ return new AFPData( AFPData::DString, preg_quote( $string ) );
 1756+ }
 1757+
17461758 protected function funcSetVar( $args ) {
17471759 if ( count( $args ) < 2 ) {
17481760 throw new AFPUserVisibleException(

Follow-up revisions

RevisionCommit summaryAuthorDate
r100256Add comment explaining why we do not need second parameter to preg_quote, per...vasilievvv18:57, 19 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r100135* (bug 24109) Add regex escaping function to abuse filtervasilievvv17:54, 18 October 2011

Comments

#Comment by Nikerabbit (talk | contribs)   05:51, 19 October 2011

preg_quote should always be used with the second parameter.

#Comment by Nikerabbit (talk | contribs)   05:53, 19 October 2011

Okay, even if it doesn't need to here, it should be explicitly stated why not.

#Comment by VasilievVV (talk | contribs)   18:58, 19 October 2011

Fixed in r100256.

Status & tagging log