reactjs/react-router-redux

uri encode have a bug it is work on chrome

wollld opened this issue · 1 comments

bug tip on ios:
URIError: Pathname "/RadioSelect/title=%CA))%14%0EH7&items=%0F%E8|t)|4)&index=3&value=" could not be decoded. This is likely caused by an invalid percent-encoding.

use encode:
jumpToSelect(e) {
        //console.log(e.target.style)
        let obj= {
            title: this.props.name,
            items: this.props.items,
            index: this.props.index,
            value: this.props.value,
            items1: this.props.items1,
            content: this.props.content
        };
        console.log(obj2String(obj))
        this.props.dispatch( push(`/${this.props.to}/${obj2String(obj)}`) )
}

defined:
export function obj2String(queryObj){
    //{a:b,c:d}
    console.log("queryobj:",queryObj)
    let queryStr="";
    for(let i in queryObj){
        if(typeof queryObj[i]==="string"||typeof queryObj[i]==="number"||typeof queryObj[i]==="boolean"){
            //queryStr+= (i+"="+encodeURIComponent(queryObj[i])+"&");
            queryStr+= (i+"="+queryObj[i]+"&");
        }
        if(Reflect.apply(Object.prototype.toString,queryObj[i],[])==="[object Array]"){
            let str="";
            queryObj[i].forEach((v)=>{
                str+= v+"|";
            });
            str= str?str.substring(0,str.length-1):str;
            //queryStr+=i+"="+encodeURIComponent(str)+"&";
            queryStr+=i+"="+str+"&";
        }
    }
    console.log("encode:",queryStr)
    let str= /&$/.test(queryStr)?queryStr.substring(0,queryStr.length-1):queryStr;
    return encodeURIComponent(str);

}

This is a bug tracker, not a support system. For usage questions, please use Stack Overflow or Reactiflux. Thanks!