r80025 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80024‎ | r80025 | r80026 >
Date:18:38, 11 January 2011
Author:platonides
Status:resolved (Comments)
Tags:
Comment:
Forbid '<', '>', ' ', '\n', '\r' in parser hook names.
Registering a tag hook with < or > on its name resulted in a UNIQ marker.
Spaces, tabs or LF do work (CR fails due to the CR->LF transformation),
but it's easier to also forbid them, just as they are not allowed in other
markup languages.
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -4315,6 +4315,7 @@
43164316 */
43174317 public function setHook( $tag, $callback ) {
43184318 $tag = strtolower( $tag );
 4319+ if ( preg_match( '/[<> \r\n]/', $tag, $m ) ) throw new MWException( "Invalid character {$m[0]} in setHook('$tag', ...) call" );
43194320 $oldVal = isset( $this->mTagHooks[$tag] ) ? $this->mTagHooks[$tag] : null;
43204321 $this->mTagHooks[$tag] = $callback;
43214322 if ( !in_array( $tag, $this->mStripList ) ) {
@@ -4326,6 +4327,7 @@
43274328
43284329 function setTransparentTagHook( $tag, $callback ) {
43294330 $tag = strtolower( $tag );
 4331+ if ( preg_match( '/[<> \r\n]/', $tag, $m ) ) throw new MWException( "Invalid character {$m[0]} in setHook('$tag', ...) call" );
43304332 $oldVal = isset( $this->mTransparentTagHooks[$tag] ) ? $this->mTransparentTagHooks[$tag] : null;
43314333 $this->mTransparentTagHooks[$tag] = $callback;
43324334
@@ -4430,6 +4432,7 @@
44314433 */
44324434 function setFunctionTagHook( $tag, $callback, $flags ) {
44334435 $tag = strtolower( $tag );
 4436+ if ( preg_match( '/[<> \r\n]/', $tag, $m ) ) throw new MWException( "Invalid character {$m[0]} in setHook('$tag', ...) call" );
44344437 $old = isset( $this->mFunctionTagHooks[$tag] ) ?
44354438 $this->mFunctionTagHooks[$tag] : null;
44364439 $this->mFunctionTagHooks[$tag] = array( $callback, $flags );

Follow-up revisions

RevisionCommit summaryAuthorDate
r80065Follow up r80025....platonides00:11, 12 January 2011
r80416Pasting lines typo in r80025platonides16:41, 16 January 2011
r80461Follow up r80376. Added missing file FORMAT....platonides19:54, 17 January 2011

Comments

#Comment by Raymond (talk | contribs)   20:39, 11 January 2011

Is it really necessary to forbid spaces? On TWN we get a lot of exception now like

 /wiki/Main_Page: Exception: Invalid character in setHook('display map', ...) call
#Comment by Platonides (talk | contribs)   23:51, 11 January 2011

It is not, but they would make detecting the tags easier.

What extension is calling 'display map'? The most similar I find is Maps registering display_map (via Validator extension so that it can't be grepped for) but I do not see any 'display map'.

#Comment by Platonides (talk | contribs)   00:07, 12 January 2011

Found, it changes underscores to spaces just before callign setHook()

Status & tagging log