blogger
Revisão | eae24a4e3d1e0698bad43633297d2a6f8b595174 (tree) |
---|---|
Hora | 2021-05-02 23:38:15 |
Autor | umorigu <umorigu@gmai...> |
Commiter | umorigu |
BugTrack/2512 preg_replace with PCRE_UTF8 (/u) option (AutoLink)
* BugTrack/2512 AutoAlias fail for some specific chars
* BugTrack/2518 AutoLink fail for some specific chars
Set /xu option for preg_replace() with /x
@@ -800,6 +800,7 @@ function get_autoaliases() | ||
800 | 800 | { |
801 | 801 | global $aliaspage, $autoalias_max_words; |
802 | 802 | static $pairs; |
803 | + $preg_u = get_preg_u(); | |
803 | 804 | |
804 | 805 | if (! isset($pairs)) { |
805 | 806 | $pairs = array(); |
@@ -813,7 +814,8 @@ EOD; | ||
813 | 814 | $matches = array(); |
814 | 815 | $count = 0; |
815 | 816 | $max = max($autoalias_max_words, 0); |
816 | - if (preg_match_all('/' . $pattern . '/x', $postdata, $matches, PREG_SET_ORDER)) { | |
817 | + if (preg_match_all('/' . $pattern . '/x' . get_preg_u(), $postdata, | |
818 | + $matches, PREG_SET_ORDER)) { | |
817 | 819 | foreach($matches as $key => $value) { |
818 | 820 | if ($count == $max) break; |
819 | 821 | $name = trim($value[1]); |
@@ -1157,6 +1159,22 @@ function manage_page_redirect() { | ||
1157 | 1159 | return FALSE; |
1158 | 1160 | } |
1159 | 1161 | |
1162 | +/** | |
1163 | + * Return 'u' (PCRE_UTF8) if PHP7+ and UTF-8. | |
1164 | + */ | |
1165 | +function get_preg_u() { | |
1166 | + static $utf8u; // 'u'(PCRE_UTF8) or '' | |
1167 | + if (! isset($utf8u)) { | |
1168 | + if (version_compare('7.0.0', PHP_VERSION, '<=') | |
1169 | + && defined('PKWK_UTF8_ENABLE')) { | |
1170 | + $utf8u = 'u'; | |
1171 | + } else { | |
1172 | + $utf8u = ''; | |
1173 | + } | |
1174 | + } | |
1175 | + return $utf8u; | |
1176 | +} | |
1177 | + | |
1160 | 1178 | //// Compat //// |
1161 | 1179 | |
1162 | 1180 | // is_a -- Returns TRUE if the object is of this class or has this class as one of its parents |
@@ -425,7 +425,8 @@ $BracketName = '(?!\s):?[^\r\n\t\f\[\]<>#&":]+:?(?<!\s)'; | ||
425 | 425 | $InterWikiName = '(\[\[)?((?:(?!\s|:|\]\]).)+):(.+)(?(1)\]\])'; |
426 | 426 | |
427 | 427 | // 注釈 |
428 | -$NotePattern = '/\(\(((?:(?>(?:(?!\(\()(?!\)\)(?:[^\)]|$)).)+)|(?R))*)\)\)/x'; | |
428 | +$NotePattern = '/\(\(((?:(?>(?:(?!\(\()(?!\)\)(?:[^\)]|$)).)+)|(?R))*)\)\)/x' | |
429 | + . get_preg_u(); | |
429 | 430 | |
430 | 431 | ///////////////////////////////////////////////// |
431 | 432 | // 初期設定(ユーザ定義ルール読み込み) |
@@ -117,7 +117,7 @@ class InlineConverter | ||
117 | 117 | $this->page = $page; |
118 | 118 | $this->result = array(); |
119 | 119 | |
120 | - $string = preg_replace_callback('/' . $this->pattern . '/x', | |
120 | + $string = preg_replace_callback('/' . $this->pattern . '/x' . get_preg_u(), | |
121 | 121 | array(& $this, 'replace'), $string); |
122 | 122 | |
123 | 123 | $arr = explode("\x08", make_line_rules(htmlsc($string))); |
@@ -141,7 +141,8 @@ class InlineConverter | ||
141 | 141 | function get_objects($string, $page) |
142 | 142 | { |
143 | 143 | $matches = $arr = array(); |
144 | - preg_match_all('/' . $this->pattern . '/x', $string, $matches, PREG_SET_ORDER); | |
144 | + preg_match_all('/' . $this->pattern . '/x' . get_preg_u(), | |
145 | + $string, $matches, PREG_SET_ORDER); | |
145 | 146 | foreach ($matches as $match) { |
146 | 147 | $obj = $this->get_converter($match); |
147 | 148 | if ($obj->set($match, $page) !== FALSE) { |
@@ -281,7 +282,7 @@ EOD; | ||
281 | 282 | |
282 | 283 | // Re-get true plugin name and patameters (for PHP 4.1.2) |
283 | 284 | $matches = array(); |
284 | - if (preg_match('/^' . $this->pattern . '/x', $all, $matches) | |
285 | + if (preg_match('/^' . $this->pattern . '/x' . get_preg_u(), $all, $matches) | |
285 | 286 | && $matches[1] != $this->plain) |
286 | 287 | list(, $this->plain, $name, $this->param) = $matches; |
287 | 288 |