r31804 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r31803‎ | r31804 | r31805 >
Date:17:56, 11 March 2008
Author:mkroetzsch
Status:old
Tags:
Comment:
Protect all preg_* against UTF8 hassles using /u, see Bug 13321.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_GeoCoords.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Linear.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Number.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_URI.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Hooks.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Infolink.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Timeline.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php
@@ -156,7 +156,7 @@
157157 // foreach ($outrel as $result) {
158158 // $objectoptions = new SMWRequestOptions();
159159 // $objectoptions->limit = $innerlimit;
160 -// $html .= '<strong>' . $skin->makeKnownLinkObj($result, preg_replace('/[\s]/', '&nbsp;', smwfT($result), 2)) . "</strong>&nbsp; \n";// TODO makeLinkObj or makeKnownLinkObj?
 160+// $html .= '<strong>' . $skin->makeKnownLinkObj($result, preg_replace('/[\s]/u', '&nbsp;', smwfT($result), 2)) . "</strong>&nbsp; \n";// TODO makeLinkObj or makeKnownLinkObj?
161161 // $objects = &smwfGetStore()->getRelationObjects($article, $result, $objectoptions);
162162 // $objectcount = count($objects);
163163 // $count = 0;
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Linear.php
@@ -171,7 +171,7 @@
172172 if (!$numdv->isValid() || ($numdv->getNumericValue() === 0)) {
173173 continue; // ignore problmatic conversions
174174 }
175 - $unit_aliases = preg_split('/\s*,\s*/', $numdv->getUnit());
 175+ $unit_aliases = preg_split('/\s*,\s*/u', $numdv->getUnit());
176176 $first = true;
177177 foreach ($unit_aliases as $unit) {
178178 $unit = $this->normalizeUnit($unit);
@@ -204,7 +204,7 @@
205205 $values = smwfGetStore()->getSpecialValues($proptitle, SMW_SP_DISPLAY_UNITS);
206206 $units = array();
207207 foreach ($values as $value) { // Join all if many annotations exist. Discouraged (random order) but possible.
208 - $units = $units + preg_split('/\s*,\s*/',$value->getXSDValue());
 208+ $units = $units + preg_split('/\s*,\s*/u',$value->getXSDValue());
209209 }
210210 foreach ($units as $unit) {
211211 $unit = $this->normalizeUnit($unit);
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
@@ -101,7 +101,7 @@
102102 foreach ($servicelinks as $dvs) {
103103 $args[0] = 'smw_service_' . str_replace(' ', '_', $dvs); // messages distinguish ' ' from '_'
104104 $text = call_user_func_array('wfMsgForContent', $args);
105 - $links = preg_split("([\n][\s]?)", $text);
 105+ $links = preg_split("/[\n][\s]?/u", $text);
106106 foreach ($links as $link) {
107107 $linkdat = explode('|',$link,2);
108108 if (count($linkdat) == 2)
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_GeoCoords.php
@@ -41,7 +41,7 @@
4242 $value = str_replace(array('&#8243;', '&Prime;', "''", '"', '´´', SMW_GEO_MIN . SMW_GEO_MIN),SMW_GEO_SEC,$value);
4343 $value = str_replace(array('&#8242;', '&prime;', "'", '´'),SMW_GEO_MIN,$value);
4444 // now split the string
45 - $parts = preg_split('/\s*(°|' . SMW_GEO_MIN . '|' . SMW_GEO_SEC . '|N|E|W|S|;)\s*/',str_replace(', ', ';', $value) . ';', -1, PREG_SPLIT_DELIM_CAPTURE);
 45+ $parts = preg_split('/\s*(°|' . SMW_GEO_MIN . '|' . SMW_GEO_SEC . '|N|E|W|S|;)\s*/u',str_replace(', ', ';', $value) . ';', -1, PREG_SPLIT_DELIM_CAPTURE);
4646 $curnum = false;
4747 $angles = array(false, false, false); // temporary values for deg, min, sec
4848 foreach ($parts as $part) {
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Hooks.php
@@ -43,7 +43,7 @@
4444 )*) # all this zero or more times
4545 (\|([^]]*))? # Display text (like "text" in [[link|text]]), optional
4646 \]\] # End of link
47 - /x';
 47+ /xu';
4848 $text = preg_replace_callback($semanticLinkPattern, 'smwfParsePropertiesCallback', $text);
4949
5050 SMWFactbox::printFactbox($text);
@@ -85,7 +85,7 @@
8686 } else { $valueCaption = false; }
8787
8888 //extract annotations and create tooltip
89 - $properties = preg_split('/:[=:]/', $property);
 89+ $properties = preg_split('/:[=:]/u', $property);
9090 foreach($properties as $singleprop) {
9191 $dv = SMWFactbox::addProperty($singleprop,$value,$valueCaption, $smwgStoreAnnotations && $smwgTempStoreAnnotations);
9292 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php
@@ -113,7 +113,7 @@
114114 global $wgContLang;
115115
116116 list($onto_ns,$onto_section) = explode(':',$value,2);
117 - $msglines = preg_split("([\n][\s]?)",wfMsgForContent("smw_import_$onto_ns")); // get the definition for "$namespace:$section"
 117+ $msglines = preg_split("/[\n][\s]?/u",wfMsgForContent("smw_import_$onto_ns")); // get the definition for "$namespace:$section"
118118
119119 if ( count($msglines) < 2 ) { //error: no elements for this namespace
120120 /// TODO: use new Error DV
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_URI.php
@@ -49,7 +49,7 @@
5050 $value = 'http://' . $value;
5151 $parts[1] = $parts[0];
5252 $parts[0] = 'http';
53 - } elseif ( (count($parts) < 1) || ($parts[0] == '') || ($parts[1] == '') || (preg_match('/[^a-zA-Z]/',$parts[0]) )) {
 53+ } elseif ( (count($parts) < 1) || ($parts[0] == '') || ($parts[1] == '') || (preg_match('/[^a-zA-Z]/u',$parts[0]) )) {
5454 $this->addError(wfMsgForContent('smw_baduri', $value));
5555 return true;
5656 }
@@ -63,7 +63,7 @@
6464 }
6565 }
6666 // simple check for invalid characters: ' ', '{', '}'
67 -// $check1 = "@(\}|\{| )+@";
 67+// $check1 = "@(\}|\{| )+@u";
6868 // if (preg_match($check1, $value, $matches)) {
6969 // $this->addError(wfMsgForContent('smw_baduri', $value));
7070 // break;
@@ -71,7 +71,7 @@
7272 /// TODO: the remaining checks need improvement
7373 // // validate last part of URI (after #) if provided
7474 // $uri_ex = explode('#',$value);
75 -// $check2 = "@^[a-zA-Z0-9-_\%]+$@"; ///FIXME: why only ascii symbols?
 75+// $check2 = "@^[a-zA-Z0-9-_\%]+$@u"; ///FIXME: why only ascii symbols?
7676 // if(sizeof($uri_ex)>2 ){ // URI should only contain at most one '#'
7777 // $this->addError(wfMsgForContent('smw_baduri', $value) . 'Debug3');
7878 // break;
@@ -103,7 +103,7 @@
104104 }
105105 break;
106106 case SMW_URI_MODE_EMAIL:
107 - $check = "#^([_a-zA-Z0-9-]+)((\.[_a-zA-Z0-9-]+)*)@([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*)\.([a-zA-Z]{2,3})$#";
 107+ $check = "#^([_a-zA-Z0-9-]+)((\.[_a-zA-Z0-9-]+)*)@([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*)\.([a-zA-Z]{2,3})$#u";
108108 if (!preg_match($check, $value)) {
109109 ///TODO: introduce error-message for "bad" email
110110 $this->addError(wfMsgForContent('smw_baduri', $value));
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -723,7 +723,7 @@
724724 if ($value == '*') { // printout statement
725725 return;
726726 }
727 - $list = preg_split('/^(' . $smwgQComparators . ')/',$value, 2, PREG_SPLIT_DELIM_CAPTURE);
 727+ $list = preg_split('/^(' . $smwgQComparators . ')/u',$value, 2, PREG_SPLIT_DELIM_CAPTURE);
728728 $comparator = SMW_CMP_EQ;
729729 if (count($list) == 3) { // initial comparator found ($list[1] should be empty)
730730 switch ($list[1]) {
@@ -855,7 +855,7 @@
856856 if ($stoppattern == '') {
857857 $stoppattern = '\[\[|\]\]|::|:=|<q>|<\/q>|^' . $this->m_categoryprefix . '|\|\||\|';
858858 }
859 - $chunks = preg_split('/[\s]*(' . $stoppattern . ')[\s]*/', $this->m_curstring, 2, PREG_SPLIT_DELIM_CAPTURE);
 859+ $chunks = preg_split('/[\s]*(' . $stoppattern . ')[\s]*/u', $this->m_curstring, 2, PREG_SPLIT_DELIM_CAPTURE);
860860 if (count($chunks) == 1) { // no matches anymore, strip spaces and finish
861861 if ($consume) {
862862 $this->m_curstring = '';
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Timeline.php
@@ -36,7 +36,7 @@
3737 }
3838 if (array_key_exists('timelinebands', $params)) {
3939 //check for band parameter, should look like "DAY,MONTH,YEAR"
40 - $this->m_tlbands = preg_split('/[,][\s]*/',trim($params['timelinebands']));
 40+ $this->m_tlbands = preg_split('/[,][\s]*/u',trim($params['timelinebands']));
4141 } else {
4242 $this->m_tlbands = array('MONTH','YEAR'); /// TODO: check what default the JavaScript uses
4343 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Infolink.php
@@ -103,7 +103,7 @@
104104 $end = '';
105105 }
106106 if ($this->internal) {
107 - if (preg_match('/(.*)(\[|\]|<|>|&gt;|&lt;|\'\'|{|})(.*)/', $this->target) != 0 ) {
 107+ if (preg_match('/(.*)(\[|\]|<|>|&gt;|&lt;|\'\'|{|})(.*)/u', $this->target) != 0 ) {
108108 return ''; // give up if illegal characters occur,
109109 // TODO: we would need a skin to provide an ext URL in this case
110110 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Number.php
@@ -42,12 +42,12 @@
4343 $kiloseparator = wfMsgForContent('smw_kiloseparator');
4444
4545 $parts = preg_split('/([-+]?\s*\d+(?:\\' . $kiloseparator . '\d\d\d)*' .
46 - '(?:\\' . $decseparator . '\d+)?\s*(?:[eE][-+]?\d+)?)/',
 46+ '(?:\\' . $decseparator . '\d+)?\s*(?:[eE][-+]?\d+)?)/u',
4747 trim(str_replace(array('&nbsp;','&thinsp;'), '', $value)),
4848 2, PREG_SPLIT_DELIM_CAPTURE);
4949
5050 if (count($parts) >= 2) {
51 - $numstring = str_replace($kiloseparator, '', preg_replace('/\s*/', '', $parts[1])); // simplify
 51+ $numstring = str_replace($kiloseparator, '', preg_replace('/\s*/u', '', $parts[1])); // simplify
5252 if ($decseparator != '.') {
5353 $numstring = str_replace($decseparator, '.', $numstring);
5454 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php
@@ -547,7 +547,7 @@
548548 // Should we use decimal places here?
549549 $value = sprintf("%1.6e", $value);
550550 // Make it more readable by removing trailing zeroes from n.n00e7.
551 - $value = preg_replace('/(\\.\\d+?)0*e/', '${1}e', $value, 1);
 551+ $value = preg_replace('/(\\.\\d+?)0*e/u', '${1}e', $value, 1);
552552 //NOTE: do not use the optional $count parameter with preg_replace. We need to
553553 // remain compatible with PHP 4.something.
554554 if ($decseparator !== '.') {
@@ -567,7 +567,7 @@
568568 } else {
569569 // If above replacement occurred, no need to do the next one.
570570 // Make it more readable by removing trailing zeroes from nn.n00.
571 - $value = preg_replace("/(\\$decseparator\\d+?)0*$/", '$1', $value, 1);
 571+ $value = preg_replace("/(\\$decseparator\\d+?)0*$/u", '$1', $value, 1);
572572 }
573573 }
574574 return $value;
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php
@@ -43,7 +43,7 @@
4444 }
4545
4646 $types = $this->m_type->getTypeValues();
47 - $values = preg_split('/[\s]*;[\s]*/', trim($value), $this->m_count);
 47+ $values = preg_split('/[\s]*;[\s]*/u', trim($value), $this->m_count);
4848 $vi = 0; // index in value array
4949 $empty = true;
5050 for ($i = 0; $i < $this->m_count; $i++) { // iterate over slots

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r31787Added quickfixes as suggested for Bug 13321mkroetzsch15:28, 11 March 2008

Status & tagging log