}
# Clean up special characters, only run once, next-to-last before doBlockLevels
- $fixtags = [
- # French spaces, last one Guillemet-left
- # only if there is something before the space
- '/(.) (?=\\?|:|;|!|%|\\302\\273)/' => '\\1 ',
- # french spaces, Guillemet-right
- '/(\\302\\253) /' => '\\1 ',
- '/ (!\s*important)/' => ' \\1', # Beware of CSS magic word !important, T13874.
- ];
- $text = preg_replace( array_keys( $fixtags ), array_values( $fixtags ), $text );
+ $text = Sanitizer::armorFrenchSpaces( $text );
$text = $this->doBlockLevels( $text, $linestart );
return $encValue;
}
+ /**
+ * Armor French spaces with a replacement character
+ *
+ * @since 1.32
+ * @param string $text Text to armor
+ * @param string $space Space character for the French spaces, defaults to ' '
+ * @return string Armored text
+ */
+ public static function armorFrenchSpaces( $text, $space = ' ' ) {
+ // Replace $ with \$ and \ with \\
+ $space = preg_replace( '#(?<!\\\\)(\\$|\\\\)#', '\\\\$1', $space );
+ $fixtags = [
+ # French spaces, last one Guillemet-left
+ # only if there is something before the space
+ '/(.) (?=\\?|:|;|!|%|\\302\\273)/' => "\\1$space",
+ # French spaces, Guillemet-right
+ '/(\\302\\253) /' => "\\1$space",
+ ];
+ return preg_replace( array_keys( $fixtags ), array_values( $fixtags ), $text );
+ }
+
/**
* Encode an attribute value for HTML tags, with extra armoring
* against further wiki processing.
'__' => '__',
] );
+ # Armor against French spaces detection (T5158)
+ $encValue = self::armorFrenchSpaces( $encValue, ' ' );
+
# Stupid hack
$encValue = preg_replace_callback(
'/((?i)' . wfUrlProtocols() . ')/',
!! html/php
<table>
<tr>
-<td><div style="color: red !important;" data-contrived="put this here ||">hi</div>
+<td><div style="color: red !important;" data-contrived="put this here ||">hi</div>
</td></tr></table>
!! html/parsoid
!! html/php
<table>
<tr>
-<td>style="color: red !important;" data-contrived="put this here</td>
+<td>style="color: red !important;" data-contrived="put this here</td>
<td>foo
</td></tr></table>
!! wikitext
<div style="width:50% !important">important</div>
!! html
-<div style="width:50% !important">important</div>
+<div style="width:50% !important">important</div>
!!end
!! wikitext
<div style="width:50% ! important">important</div>
!! html
-<div style="width:50% ! important">important</div>
+<div style="width:50% ! important">important</div>
!!end
<div style="width:50% !important"> </div>
<div style="border : solid;"> </div>
!! html/php
-<div style="width:50% !important"> </div>
+<div style="width:50% !important"> </div>
<div style="width:50% !important"> </div>
<div style="width:50% !important"> </div>
-<div style="border : solid;"> </div>
+<div style="border : solid;"> </div>
!! html/parsoid
<div style="width:50% !important" data-parsoid='{"stx":"html"}'><span typeof="mw:Entity" data-parsoid='{"srcContent":" "}'> </span></div>
!! end
+!! test
+T5158: Test for French spaces in attributes
+!! wikitext
+<br style=" clear : both ; " />
+!! html/php
+<p><br style="clear : both ;" />
+</p>
+!! end
+
!! test
HTML5 data attributes
!! wikitext