From: umherirrender
Date: Tue, 17 Dec 2013 18:14:15 +0000 (+0100)
Subject: Raw option of parser functions should match complete word
X-Git-Tag: 1.31.0-rc.0~17274
X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/pie.php?a=commitdiff_plain;h=cf5cb9b79add6cd2b8ca27565e75765bbd677361;p=lhc%2Fweb%2Fwiklou.git
Raw option of parser functions should match complete word
The MagicWord raw was not matched against the whole given string, which
result in a raw output, when this was not intented.
Fixing this by adding a new regex, which matches the string from start
to end.
Bug: 56199
Change-Id: I7781c415bd61447dd91872575877dd21f36fae9f
---
diff --git a/RELEASE-NOTES-1.23 b/RELEASE-NOTES-1.23
index 1bdce42a13..b0d97aa809 100644
--- a/RELEASE-NOTES-1.23
+++ b/RELEASE-NOTES-1.23
@@ -104,6 +104,8 @@ production.
templatelinks does).
* (bug 58167) The web installer no longer throws an exception when PHP is
compiled without support for MySQL yet with support for another DBMS.
+* (bug 56199) Raw option of parser functions must now match complete word,
+ to take effect.
=== Web API changes in 1.23 ===
* (bug 54884) action=parse&prop=categories now indicates hidden and missing
diff --git a/includes/MagicWord.php b/includes/MagicWord.php
index bf15bf34a7..377d406494 100644
--- a/includes/MagicWord.php
+++ b/includes/MagicWord.php
@@ -65,6 +65,7 @@ class MagicWord {
var $mId, $mSynonyms, $mCaseSensitive;
var $mRegex = '';
var $mRegexStart = '';
+ var $mRegexStartToEnd = '';
var $mBaseRegex = '';
var $mVariableRegex = '';
var $mVariableStartToEndRegex = '';
@@ -339,6 +340,7 @@ class MagicWord {
$case = $this->mCaseSensitive ? '' : 'iu';
$this->mRegex = "/{$this->mBaseRegex}/{$case}";
$this->mRegexStart = "/^(?:{$this->mBaseRegex})/{$case}";
+ $this->mRegexStartToEnd = "/^(?:{$this->mBaseRegex})$/{$case}";
$this->mVariableRegex = str_replace( "\\$1", "(.*?)", $this->mRegex );
$this->mVariableStartToEndRegex = str_replace( "\\$1", "(.*?)",
"/^(?:{$this->mBaseRegex})$/{$case}" );
@@ -405,6 +407,19 @@ class MagicWord {
return $this->mRegexStart;
}
+ /**
+ * Gets a regex matching the word from start to end of a string
+ *
+ * @return string
+ * @since 1.23
+ */
+ function getRegexStartToEnd() {
+ if ( $this->mRegexStartToEnd == '' ) {
+ $this->initRegex();
+ }
+ return $this->mRegexStartToEnd;
+ }
+
/**
* regex without the slashes and what not
*
@@ -439,6 +454,18 @@ class MagicWord {
return (bool)preg_match( $this->getRegexStart(), $text );
}
+ /**
+ * Returns true if the text matched the word
+ *
+ * @param $text string
+ *
+ * @return bool
+ * @since 1.23
+ */
+ function matchStartToEnd( $text ) {
+ return (bool)preg_match( $this->getRegexStartToEnd(), $text );
+ }
+
/**
* Returns NULL if there's no match, the value of $1 otherwise
* The return code is the matched string, if there's no variable
diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php
index 250442c831..df0f1187cb 100644
--- a/includes/parser/CoreParserFunctions.php
+++ b/includes/parser/CoreParserFunctions.php
@@ -402,11 +402,12 @@ class CoreParserFunctions {
* @return boolean true on successful match
*/
private static function matchAgainstMagicword( $magicword, $value ) {
- if ( strval( $value ) === '' ) {
+ $value = trim( strval( $value ) );
+ if ( $value === '' ) {
return false;
}
$mwObject = MagicWord::get( $magicword );
- return $mwObject->match( $value );
+ return $mwObject->matchStartToEnd( $value );
}
static function formatRaw( $num, $raw ) {
diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt
index ce2c73406a..6dff54e5e8 100644
--- a/tests/parser/parserTests.txt
+++ b/tests/parser/parserTests.txt
@@ -16687,6 +16687,19 @@ language=be-tarask
!! end
+!! test
+Wrong option for formatNum (bug 56199)
+!! input
+{{formatnum:1,234.56|Random}}
+{{formatnum:1,234.56|EVERYTHING}}
+{{formatnum:1234.56|any argument that has the string 'NOSEP'}}
+!! result
+1,234.56
+1,234.56
+1,234.56
+
+!! end
+
!! test
Strip marker in grammar
!! options