github主线上对“order解析的完善”存在bug

浏览:573 发布日期:2015/11/05
3.2.3 - 严重 - 已处理
M('SystemData')->field('value')->where(array('key' => 'site'))->find();会出现SQL错误:......`key` = 'site' ORDER BY `` LIMIT 1
跟踪代码发现是:protected function parseOrder($order)
    {
        $array = array();
        if (is_array($order)) {
            foreach ($order as $key => $val) {
                if (is_numeric($key)) {
                    if (false === strpos($val, '(')) {
                        $array[] = $this->parseKey($val);
                    }
                } else {
                    $sort    = in_array(strtolower($val), array('asc', 'desc')) ? ' ' . $val : '';
                    $array[] = $this->parseKey($key) . $sort;
                }
            }
        } else {
            foreach (explode(',', $order) as $val) {
                if (preg_match('/\s+(ASC|DESC)$/i', rtrim($val), $match, PREG_OFFSET_CAPTURE)) {
                    $array[] = $this->parseKey(ltrim(substr($val, 0, $match[0][1]))) . ' ' . $match[1][0];
                } elseif (false === strpos($val, '(')) {
                    $array[] = $this->parseKey($val);
                }
            }
        }
        $order = implode(',', $array);
        return !empty($order) ? ' ORDER BY ' . $order : '';
    }
未加$order为空''的判断
评论(
后面还有条评论,点击查看>>