修正由于转义引号导致的在sqlite下查询失败错误
修正由于部分主机没有安装mb插件导致无法输出markdown文本的错误

fix #288

给expression增加参数$escape来控制是否转义语句
This commit is contained in:
祁宁
2014-10-09 22:19:22 +08:00
parent 52f7f3a29a
commit 80de4900df
6 changed files with 38 additions and 22 deletions
+29
View File
@@ -48,6 +48,17 @@ class Typecho_Common
*/
public static $exceptionHandle;
/**
* 将字符串变成大写的回调函数
*
* @param array $matches
* @access public
* @return string
*/
public static function __strToUpper($matches)
{
return strtoupper($matches[0]);
}
/**
* 将url中的非法xss去掉时的数组回调过滤函数
@@ -226,6 +237,7 @@ class Typecho_Common
@ob_end_clean();
if (defined('__TYPECHO_DEBUG__')) {
echo '<h1>' . $exception->getMessage() . '</h1>';
echo nl2br($exception->__toString());
} else {
if (404 == $exception->getCode() && !empty(self::$exceptionHandle)) {
@@ -740,6 +752,23 @@ EOF;
}
}
/**
* 获取大写字符串
*
* @param string $str
* @access public
* @return string
*/
public static function strToUpper($str)
{
if (__TYPECHO_MB_SUPPORTED__) {
return mb_strtoupper($str, self::$charset);
} else {
return 'UTF-8' == strtoupper(self::$charset)
? preg_replace_callback("/[a-z]+/u", array('Typecho_Common', '__strToUpper'), $str) : strtoupper($str);
}
}
/**
* 检查是否为合法的编码数据
*
+3 -19
View File
@@ -111,26 +111,9 @@ class Typecho_Db_Query
$split = '';
$quotes = 0;
// fix issue #288
$inStr = false;
for ($i = 0; $i < $length; $i ++) {
$cha = $str[$i];
if (false !== strpos("'\"", $cha)) {
$inStr = !$inStr;
if (!$inStr) {
$result .= $cha;
continue;
}
}
if ($inStr) {
$result .= $cha;
continue;
}
if (ctype_alnum($cha) || false !== strpos('_*', $cha)) {
if (!$lastIsAlnum) {
if ($quotes > 0 && !ctype_digit($word) && '.' != $split
@@ -374,11 +357,12 @@ class Typecho_Db_Query
*
* @param string $key 栏目名称
* @param mixed $value 指定的值
* @param bool $escape 是否转义
* @return Typecho_Db_Query
*/
public function expression($key, $value)
public function expression($key, $value, $escape = true)
{
$this->_sqlPreBuild['rows'][$this->filterColumn($key)] = $this->filterColumn($value);
$this->_sqlPreBuild['rows'][$this->filterColumn($key)] = $escape ? $this->filterColumn($value) : $value;
return $this;
}