Replace our mbstring polyfills with symfony/polyfill-mbstring
The symfony/polyfill-mbstring is anyway pulled in through Twig, so this doesn't add additional dependencies. Fixes #12386 Signed-off-by: Michal Čihař <michal@cihar.com>
This commit is contained in:
parent
ce78e2f154
commit
7cea5eb9af
@ -33,7 +33,6 @@
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.5.0",
|
||||
"ext-mbstring": "*",
|
||||
"ext-mysqli": "*",
|
||||
"ext-xml": "*",
|
||||
"ext-pcre": "*",
|
||||
@ -46,7 +45,8 @@
|
||||
"psr/container": "^1.0",
|
||||
"twig/twig": "^1.32",
|
||||
"twig/extensions": "~1.4.1",
|
||||
"symfony/expression-language": "^3.2"
|
||||
"symfony/expression-language": "^3.2",
|
||||
"symfony/polyfill-mbstring": "^1.3"
|
||||
},
|
||||
"conflict": {
|
||||
"tecnickcom/tcpdf": "<6.2"
|
||||
@ -59,6 +59,7 @@
|
||||
"ext-bz2": "For bzip2 import and export",
|
||||
"ext-zip": "For zip import and export",
|
||||
"ext-gd2": "For image transformations",
|
||||
"ext-mbstring": "For best performance",
|
||||
"tecnickcom/tcpdf": "For PDF support"
|
||||
},
|
||||
"require-dev": {
|
||||
|
||||
@ -13,7 +13,10 @@ PHP
|
||||
---
|
||||
|
||||
* You need PHP 5.5.0 or newer, with ``session`` support, the Standard PHP Library
|
||||
(SPL) extension, JSON support, and the ``mbstring`` extension (see :term:`mbstring`).
|
||||
(SPL) extension, and JSON support.
|
||||
|
||||
* The ``mbstring`` extension (see :term:`mbstring`) is strongly recommended
|
||||
for performance reasons.
|
||||
|
||||
* To support uploading of ZIP files, you need the PHP ``zip`` extension.
|
||||
|
||||
|
||||
@ -195,10 +195,7 @@ class Encoding
|
||||
*/
|
||||
public static function canConvertKanji()
|
||||
{
|
||||
return (
|
||||
$GLOBALS['lang'] == 'ja' &&
|
||||
function_exists('mb_convert_encoding')
|
||||
);
|
||||
return $GLOBALS['lang'] == 'ja';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -818,13 +818,7 @@ class FormDisplay
|
||||
'recode', 'recode'
|
||||
);
|
||||
}
|
||||
if (!function_exists('mb_convert_encoding')) {
|
||||
$opts['values']['mb'] .= ' (' . __('unavailable') . ')';
|
||||
$comment .= ($comment ? ", " : '') . sprintf(
|
||||
__('"%s" requires %s extension'),
|
||||
'mb', 'mbstring'
|
||||
);
|
||||
}
|
||||
/* mbstring is always there thanks to polyfill */
|
||||
$opts['comment'] = $comment;
|
||||
$opts['comment_warning'] = true;
|
||||
}
|
||||
|
||||
@ -17,11 +17,6 @@ if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* String handling (security)
|
||||
*/
|
||||
require_once 'libraries/string.lib.php';
|
||||
|
||||
/**
|
||||
* checks given $var and returns it if valid, or $default of not valid
|
||||
* given $var is also checked for type being 'similar' as $default
|
||||
@ -235,15 +230,7 @@ function PMA_fatalError($error_message, $message_args = null) {
|
||||
$response->addJSON('message', PMA\libraries\Message::error($error_message));
|
||||
} else {
|
||||
$error_message = strtr($error_message, array('<br />' => '[br]'));
|
||||
|
||||
// these variables are used in the included file libraries/error.inc.php
|
||||
//first check if php-mbstring is available
|
||||
if (function_exists('mb_detect_encoding')) {
|
||||
//If present use gettext
|
||||
$error_header = __('Error');
|
||||
} else {
|
||||
$error_header = 'Error';
|
||||
}
|
||||
$error_header = __('Error');
|
||||
$lang = isset($GLOBALS['lang']) ? $GLOBALS['lang'] : 'en';
|
||||
$dir = isset($GLOBALS['text_dir']) ? $GLOBALS['text_dir'] : 'ltr';
|
||||
|
||||
@ -916,7 +903,7 @@ function PMA_checkExtensions()
|
||||
* Warning about mbstring.
|
||||
*/
|
||||
if (! function_exists('mb_detect_encoding')) {
|
||||
PMA_warnMissingExtension('mbstring', true);
|
||||
PMA_warnMissingExtension('mbstring');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/** String Functions for phpMyAdmin
|
||||
*
|
||||
* If mb_* functions don't exist, we create the ones we need and they'll use the
|
||||
* standard string functions.
|
||||
*
|
||||
* All mb_* functions created by PMA should behave as mb_* functions.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!defined('MULTIBYTES_ON')) {
|
||||
define('MULTIBYTES_ON', true);
|
||||
define('MULTIBYTES_OFF', false);
|
||||
}
|
||||
|
||||
if (@function_exists('mb_strlen')) {
|
||||
if (!defined('MULTIBYTES_STATUS')) {
|
||||
define('MULTIBYTES_STATUS', MULTIBYTES_ON);
|
||||
}
|
||||
|
||||
include_once 'libraries/stringMb.lib.php';
|
||||
} else {
|
||||
if (!defined('MULTIBYTES_STATUS')) {
|
||||
define('MULTIBYTES_STATUS', MULTIBYTES_OFF);
|
||||
}
|
||||
|
||||
include_once 'libraries/stringNative.lib.php';
|
||||
}
|
||||
@ -1,76 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/** String Functions for phpMyAdmin
|
||||
*
|
||||
* If mb_* functions don't exist, we create the ones we need and they'll use the
|
||||
* standard string functions.
|
||||
*
|
||||
* All mb_* functions created by PMA should behave as mb_* functions.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!@function_exists('mb_ord')) {
|
||||
/**
|
||||
* Perform a regular expression match
|
||||
*
|
||||
* Take care: might not work with lookbehind expressions.
|
||||
*
|
||||
* @param string $pattern Pattern to search for
|
||||
* @param string $subject Input string
|
||||
* @param int $offset Start from search
|
||||
*
|
||||
* @return int 1 if matched, 0 if doesn't, false on failure
|
||||
*/
|
||||
function mb_preg_strpos($pattern, $subject, $offset = 0)
|
||||
{
|
||||
$matches = array();
|
||||
$bFind = preg_match(
|
||||
$pattern, mb_substr($subject, $offset), $matches, PREG_OFFSET_CAPTURE
|
||||
);
|
||||
if (1 !== $bFind) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $matches[1][1] + $offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ordinal value of a string
|
||||
*
|
||||
* @param string $string the string for which ord is required
|
||||
*
|
||||
* @return int the ord value
|
||||
*/
|
||||
function mb_ord($string)
|
||||
{
|
||||
if (false === $string || null === $string || '' === $string) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$str = mb_convert_encoding($string, "UCS-4BE", "UTF-8");
|
||||
$substr = mb_substr($str, 0, 1, "UCS-4BE");
|
||||
$val = unpack("N", $substr);
|
||||
return $val[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the character of an ASCII
|
||||
*
|
||||
* @param int $ascii the ASCII code for which character is required
|
||||
*
|
||||
* @return string the character
|
||||
*/
|
||||
function mb_chr($ascii)
|
||||
{
|
||||
return mb_convert_encoding(
|
||||
pack("N", $ascii),
|
||||
'utf-8',
|
||||
'UCS-4BE'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,245 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/** String Functions for phpMyAdmin
|
||||
* If mb_* functions don't exist, we create the ones we need and they'll use the
|
||||
* standard string functions.
|
||||
* All mb_* functions created by PMA should behave as mb_* functions.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (!defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
//Define mb_* functions if they don't exist.
|
||||
if (!@function_exists('mb_strlen')) {
|
||||
/**
|
||||
* Returns length of string depending on current charset.
|
||||
*
|
||||
* @param string $string string to count
|
||||
*
|
||||
* @return int string length
|
||||
*/
|
||||
function mb_strlen($string)
|
||||
{
|
||||
return strlen($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns substring from string, works depending on current charset.
|
||||
*
|
||||
* @param string $string string to count
|
||||
* @param int $start start of substring
|
||||
* @param int $length length of substring
|
||||
*
|
||||
* @return string the sub string
|
||||
*/
|
||||
function mb_substr($string, $start, $length = 2147483647)
|
||||
{
|
||||
if (null === $string || strlen($string) <= $start) {
|
||||
return '';
|
||||
}
|
||||
if (null === $length) {
|
||||
$length = 2147483647;
|
||||
}
|
||||
return substr($string, $start, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns number of substring from string.
|
||||
*
|
||||
* @param string $string string to check
|
||||
* @param int $needle string to count
|
||||
*
|
||||
* @return int number of substring from the string
|
||||
*/
|
||||
function mb_substrCount($string, $needle)
|
||||
{
|
||||
return substr_count($string, $needle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns position of $needle in $haystack or false if not found
|
||||
*
|
||||
* @param string $haystack the string being checked
|
||||
* @param string $needle the string to find in haystack
|
||||
* @param int $offset the search offset
|
||||
*
|
||||
* @return integer position of $needle in $haystack or false
|
||||
*/
|
||||
function mb_strpos($haystack, $needle, $offset = 0)
|
||||
{
|
||||
return strpos($haystack, $needle, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns position of $needle in $haystack - case insensitive - or false if
|
||||
* not found
|
||||
*
|
||||
* @param string $haystack the string being checked
|
||||
* @param string $needle the string to find in haystack
|
||||
* @param int $offset the search offset
|
||||
*
|
||||
* @return integer position of $needle in $haystack or false
|
||||
*/
|
||||
function mb_stripos($haystack, $needle, $offset = 0)
|
||||
{
|
||||
if (('' === $haystack || false === $haystack) && $offset >= strlen($haystack)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return stripos($haystack, $needle, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns position of last $needle in $haystack or false if not found
|
||||
*
|
||||
* @param string $haystack the string being checked
|
||||
* @param string $needle the string to find in haystack
|
||||
* @param int $offset the search offset
|
||||
*
|
||||
* @return integer position of last $needle in $haystack or false
|
||||
*/
|
||||
function mb_strrpos($haystack, $needle, $offset = 0)
|
||||
{
|
||||
return strrpos($haystack, $needle, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns position of last $needle in $haystack - case insensitive - or false
|
||||
* if not found
|
||||
*
|
||||
* @param string $haystack the string being checked
|
||||
* @param string $needle the string to find in haystack
|
||||
* @param int $offset the search offset
|
||||
*
|
||||
* @return integer position of last $needle in $haystack or false
|
||||
*/
|
||||
function mb_strripos($haystack, $needle, $offset = 0)
|
||||
{
|
||||
if (('' === $haystack || false === $haystack) && $offset >= strlen($haystack)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return strripos($haystack, $needle, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns part of $haystack string starting from and including the first
|
||||
* occurrence of $needle to the end of $haystack or false if not found
|
||||
*
|
||||
* @param string $haystack the string being checked
|
||||
* @param string $needle the string to find in haystack
|
||||
* @param bool $before_needle the part before the needle
|
||||
*
|
||||
* @return string part of $haystack or false
|
||||
*/
|
||||
function mb_strstr($haystack, $needle, $before_needle = false)
|
||||
{
|
||||
return strstr($haystack, $needle, $before_needle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns part of $haystack string starting from and including the first
|
||||
* occurrence of $needle to the end of $haystack - case insensitive - or false
|
||||
* if not found
|
||||
*
|
||||
* @param string $haystack the string being checked
|
||||
* @param string $needle the string to find in haystack
|
||||
* @param bool $before_needle the part before the needle
|
||||
*
|
||||
* @return string part of $haystack or false
|
||||
*/
|
||||
function mb_stristr($haystack, $needle, $before_needle = false)
|
||||
{
|
||||
return stristr($haystack, $needle, $before_needle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the portion of haystack which starts at the last occurrence or false
|
||||
* if not found
|
||||
*
|
||||
* @param string $haystack the string being checked
|
||||
* @param string $needle the string to find in haystack
|
||||
*
|
||||
* @return string portion of haystack which starts at the last occurrence or
|
||||
* false
|
||||
*/
|
||||
function mb_strrchr($haystack, $needle)
|
||||
{
|
||||
return strrchr($haystack, $needle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a string lowercase
|
||||
*
|
||||
* @param string $string the string being lowercased
|
||||
*
|
||||
* @return string the lower case string
|
||||
*/
|
||||
function mb_strtolower($string)
|
||||
{
|
||||
return strtolower($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a string uppercase
|
||||
*
|
||||
* @param string $string the string being uppercased
|
||||
*
|
||||
* @return string the upper case string
|
||||
*/
|
||||
function mb_strtoupper($string)
|
||||
{
|
||||
return strtoupper($string);
|
||||
}
|
||||
}
|
||||
|
||||
//New functions.
|
||||
if (!@function_exists('mb_ord')) {
|
||||
/**
|
||||
* Perform a regular expression match
|
||||
*
|
||||
* @param string $pattern Pattern to search for
|
||||
* @param string $subject Input string
|
||||
* @param int $offset Start from search
|
||||
*
|
||||
* @return int 1 if matched, 0 if doesn't, false on failure
|
||||
*/
|
||||
function mb_preg_strpos($pattern, $subject, $offset = 0)
|
||||
{
|
||||
$matches = array();
|
||||
$bFind = preg_match(
|
||||
$pattern, $subject, $matches, PREG_OFFSET_CAPTURE, $offset
|
||||
);
|
||||
if (1 !== $bFind) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $matches[1][1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ordinal value of a string
|
||||
*
|
||||
* @param string $string the string for which ord is required
|
||||
*
|
||||
* @return int the ord value
|
||||
*/
|
||||
function mb_ord($string)
|
||||
{
|
||||
return ord($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the character of an ASCII
|
||||
*
|
||||
* @param int $ascii the ASCII code for which character is required
|
||||
*
|
||||
* @return string the character
|
||||
*/
|
||||
function mb_chr($ascii)
|
||||
{
|
||||
return chr($ascii);
|
||||
}
|
||||
}
|
||||
@ -11,7 +11,6 @@
|
||||
use PMA\libraries\plugins\transformations\Text_Plain_Link;
|
||||
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'libraries/string.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
|
||||
@ -84,10 +84,6 @@ class EncodingTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testMbstring()
|
||||
{
|
||||
if (! @function_exists('mb_convert_encoding')) {
|
||||
$this->markTestSkipped('mbstring extension missing');
|
||||
}
|
||||
|
||||
Encoding::setEngine(Encoding::ENGINE_MB);
|
||||
$this->assertEquals(
|
||||
"This is the Euro symbol '?'.",
|
||||
|
||||
@ -411,6 +411,7 @@ class FormDisplayTest extends PMATestCase
|
||||
$opts = array('values' => array());
|
||||
$opts['values']['iconv'] = 'testIconv';
|
||||
$opts['values']['recode'] = 'testRecode';
|
||||
$opts['values']['mb'] = 'testMB';
|
||||
|
||||
$expect = $opts;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user