diff --git a/libraries/String.class.php b/libraries/String.class.php index 904b0595f1..a5fbe8a0ff 100644 --- a/libraries/String.class.php +++ b/libraries/String.class.php @@ -88,7 +88,8 @@ class PMA_String public function isSqlIdentifier($c, $dot_is_valid = false) { return ($this->isAlnum($c) - || ($ord_c = ord($c)) && $ord_c >= 192 && $ord_c != 215 && $ord_c != 249 + || ($ord_c = $this->ord($c)) && $ord_c >= 192 && $ord_c != 215 && + $ord_c != 249 || $c == '_' || $c == '$' || ($dot_is_valid != false && $c == '.')); @@ -147,7 +148,19 @@ class PMA_String return $this->_byte->strtolower($string); } - /** + /** + * Get the ordinal value of a string + * + * @param string $string the string for which ord is required + * + * @return string the ord value + */ + public function ord($string) + { + return $this->_byte->ord($string); + } + + /** * Checks if a character is an alphanumeric one * * @param string $c character to check for diff --git a/libraries/StringMB.class.php b/libraries/StringMB.class.php index 7044d563a3..4db0d5e7cb 100644 --- a/libraries/StringMB.class.php +++ b/libraries/StringMB.class.php @@ -72,5 +72,21 @@ class PMA_StringMB implements PMA_StringByte { return mb_strtolower($string); } + + /** + * Get the ordinal value of a multibyte string + * (Adapted from http://www.php.net/manual/en/function.ord.php#72463) + * + * @param string $string the string for which ord is required + * + * @return string the ord value + */ + public function ord($string) + { + $str = mb_convert_encoding($string, "UCS-4BE", "UTF-8"); + $substr = mb_substr($str, 0, 1, "UCS-4BE"); + $val = unpack("N", $substr); + return $val[1]; + } } ?> diff --git a/libraries/StringNative.class.php b/libraries/StringNative.class.php index dc5976fe5d..b333610a90 100644 --- a/libraries/StringNative.class.php +++ b/libraries/StringNative.class.php @@ -71,5 +71,17 @@ class PMA_StringNative implements PMA_StringByte { return strtolower($string); } + + /** + * Get the ordinal value of a string + * + * @param string $string the string for which ord is required + * + * @return string the ord value + */ + public function ord($string) + { + return ord($string); + } }; ?> diff --git a/test/libraries/PMA_string_test.php b/test/libraries/PMA_string_test.php index 2b47263ca0..a6df1897fb 100644 --- a/test/libraries/PMA_string_test.php +++ b/test/libraries/PMA_string_test.php @@ -139,9 +139,9 @@ class PMA_String_Test extends PHPUnit_Framework_TestCase array(true, 'a'), array(true, '.', true), array(false, '.'), - array(true, chr(192)), - array(false, chr(215)), - array(false, chr(249)), + array(true, 'À'), + array(false, '×'), + array(false, 'ù'), array(true, '_'), array(true, '$') );