Javascript encodeURIComponent doesn't encode single quotes

后端 未结 6 1526
刺人心
刺人心 2021-02-01 03:39

Try it out:

encodeURIComponent(\"\'@#$%^&\");

If you try this out you will see all the special characters are encoded except for the single

6条回答
  •  名媛妹妹
    2021-02-01 04:07

    You can use:

    function fixedEncodeURIComponent (str) {
      return encodeURIComponent(str).replace(/[!'()*]/g, escape);
    }
    
    fixedEncodeURIComponent("'@#$%^&");
    

    Check reference: http://mdn.beonex.com/en/JavaScript/Reference/Global_Objects/encodeURIComponent.html

提交回复
热议问题