自定义标签不能传入带"<>"括号的bug

浏览:795 发布日期:2015/01/18 分类:求助交流
比如我定义一个自定义标签 里面随便一个属性,属性名是current
这个current属性的值 可以是数字,字符串 ,但是不能是html格式的,带有尖括号的内容 '<>' ,但是因为我自定义的标签,想实现dedecms channel标签 current属性的内容,到这里就卡住了,请问这里应该这么写啊 <keke:channel  current='<a>这里面传入带html尖括号内容就会报错</a>' >
                <a href="[field:url/]">[field:title/]</a><br/>
            </keke:channel>
thinkphp报错的提示是
-----------------------------------------
Taglib.class.php 第82行
xml标签语法错误 :current="
---------------------------------------


taglib.class.php 加粗行就是报错行 第82行  //XML解析安全过滤
        $attr   =   str_replace('&','___', $attr);
        $xml    =   '<tpl><tag '.$attr.' /></tpl>';
        $xml    =   simplexml_load_string($xml);
       if(!$xml) {
            E(L('_XML_TAG_ERROR_').' : '.$attr);
        }  //这里报错
/**
     * TagLib标签属性分析 返回标签属性数组
     * @access public
     * @param string $tagStr 标签内容
     * @return array
     */
    public function parseXmlAttr($attr,$tag) {
        //XML解析安全过滤
        $attr   =   str_replace('&','___', $attr);
        $xml    =   '<tpl><tag '.$attr.' /></tpl>';
        $xml    =   simplexml_load_string($xml);
       if(!$xml) {
            E(L('_XML_TAG_ERROR_').' : '.$attr);
        }

        $xml    =   (array)($xml->tag->attributes());
        if(isset($xml['@attributes'])){
            $array  =   array_change_key_case($xml['@attributes']);
            if($array) {
                $tag    =   strtolower($tag);
                if(!isset($this->tags[$tag])){
                    // 检测是否存在别名定义
                    foreach($this->tags as $key=>$val){
                        if(isset($val['alias']) && in_array($tag,explode(',',$val['alias']))){
                            $item  =   $val;
                            break;
                        }
                    }
                }else{
                    $item  =   $this->tags[$tag];
                }            
                $attrs  = explode(',',$item['attr']);
                if(isset($item['must'])){
                    $must   =   explode(',',$item['must']);
                }else{
                    $must   =   array();
                }
                foreach($attrs as $name) {
                    if( isset($array[$name])) {
                        $array[$name] = str_replace('___','&',$array[$name]);
                    }elseif(false !== array_search($name,$must)){
                        E(L('_PARAM_ERROR_').':'.$name);
                    }
                }
                return $array;
            }
        }else{
            return array();
        }
    }
最佳答案
评论( 相关
后面还有条评论,点击查看>>