[dev] [commit] r970 - phplib
automailer at dexonline.ro
automailer at dexonline.ro
Fri Aug 30 14:24:39 EEST 2013
Author: cata
Date: Fri Aug 30 14:24:39 2013
New Revision: 970
Log:
Fix the behavior of pipe (|) characters. When the number of pipes is not
a multiple of three, escape the remaining ones and avoid truncating the
definition.
Fixes #315.
Modified:
phplib/AdminStringUtil.php
Modified: phplib/AdminStringUtil.php
==============================================================================
--- phplib/AdminStringUtil.php Fri Aug 30 10:18:07 2013 (r969)
+++ phplib/AdminStringUtil.php Fri Aug 30 14:24:39 2013 (r970)
@@ -237,10 +237,11 @@
$result = '';
$text = '';
$ref = '';
+ $prevChar = '';
$mode = 0; // 0 = not between bars; 1 = text; 2 = reference
for ($i = 0; $i < strlen($s); $i++) {
$char = $s[$i];
- if ($char == '|') {
+ if ($char == '|' && $prevChar != "\\") {
if ($mode == 2) {
$newRef = self::internalizeReference($text, $ref);
$result .= "|$text|$newRef|";
@@ -249,12 +250,20 @@
}
$mode = ($mode + 1) % 3;
} else {
- switch($mode) {
+ switch ($mode) {
case 0: $result .= $char; break;
case 1: $text .= $char; break;
case 2: $ref .= $char;
}
}
+ $prevChar = $char;
+ }
+
+ // If the number of pipes is not a multiple of three, escape the remaining pipes.
+ switch ($mode) {
+ case 0: break; // all good
+ case 1: $result .= "\\|" . $text; break;
+ case 2: $result .= "\\|" . $text . "\\|" . $ref; break;
}
return $result;
}
@@ -334,7 +343,8 @@
}
static function convertReferencesToHtml($s) {
- return preg_replace('/\|([^|]*)\|([^|]*)\|/', '<a class="ref" href="/definitie/$2">$1</a>', $s);
+ // Require that the first pipe character is not escaped (preceded by a backslash)
+ return preg_replace('/([^\\\\])\|([^|]*)\|([^|]*)\|/', '$1<a class="ref" href="/definitie/$3">$2</a>', $s);
}
/**
More information about the Dev
mailing list