• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

blogger


Commit MetaInfo

Revisãoeae24a4e3d1e0698bad43633297d2a6f8b595174 (tree)
Hora2021-05-02 23:38:15
Autorumorigu <umorigu@gmai...>
Commiterumorigu

Mensagem de Log

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

Mudança Sumário

Diff

--- a/lib/func.php
+++ b/lib/func.php
@@ -800,6 +800,7 @@ function get_autoaliases()
800800 {
801801 global $aliaspage, $autoalias_max_words;
802802 static $pairs;
803+ $preg_u = get_preg_u();
803804
804805 if (! isset($pairs)) {
805806 $pairs = array();
@@ -813,7 +814,8 @@ EOD;
813814 $matches = array();
814815 $count = 0;
815816 $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)) {
817819 foreach($matches as $key => $value) {
818820 if ($count == $max) break;
819821 $name = trim($value[1]);
@@ -1157,6 +1159,22 @@ function manage_page_redirect() {
11571159 return FALSE;
11581160 }
11591161
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+
11601178 //// Compat ////
11611179
11621180 // is_a -- Returns TRUE if the object is of this class or has this class as one of its parents
--- a/lib/init.php
+++ b/lib/init.php
@@ -425,7 +425,8 @@ $BracketName = '(?!\s):?[^\r\n\t\f\[\]<>#&":]+:?(?<!\s)';
425425 $InterWikiName = '(\[\[)?((?:(?!\s|:|\]\]).)+):(.+)(?(1)\]\])';
426426
427427 // 注釈
428-$NotePattern = '/\(\(((?:(?>(?:(?!\(\()(?!\)\)(?:[^\)]|$)).)+)|(?R))*)\)\)/x';
428+$NotePattern = '/\(\(((?:(?>(?:(?!\(\()(?!\)\)(?:[^\)]|$)).)+)|(?R))*)\)\)/x'
429+ . get_preg_u();
429430
430431 /////////////////////////////////////////////////
431432 // 初期設定(ユーザ定義ルール読み込み)
--- a/lib/make_link.php
+++ b/lib/make_link.php
@@ -117,7 +117,7 @@ class InlineConverter
117117 $this->page = $page;
118118 $this->result = array();
119119
120- $string = preg_replace_callback('/' . $this->pattern . '/x',
120+ $string = preg_replace_callback('/' . $this->pattern . '/x' . get_preg_u(),
121121 array(& $this, 'replace'), $string);
122122
123123 $arr = explode("\x08", make_line_rules(htmlsc($string)));
@@ -141,7 +141,8 @@ class InlineConverter
141141 function get_objects($string, $page)
142142 {
143143 $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);
145146 foreach ($matches as $match) {
146147 $obj = $this->get_converter($match);
147148 if ($obj->set($match, $page) !== FALSE) {
@@ -281,7 +282,7 @@ EOD;
281282
282283 // Re-get true plugin name and patameters (for PHP 4.1.2)
283284 $matches = array();
284- if (preg_match('/^' . $this->pattern . '/x', $all, $matches)
285+ if (preg_match('/^' . $this->pattern . '/x' . get_preg_u(), $all, $matches)
285286 && $matches[1] != $this->plain)
286287 list(, $this->plain, $name, $this->param) = $matches;
287288