How to know if a URL is decoded/encoded?

后端 未结 5 799
后悔当初
后悔当初 2021-02-05 04:37

I am using Javascript method decodeURIComponent to decode an encoded URL. Now I am having an issue, that sometimes the URL is get encoded twice during redirection b

5条回答
  •  被撕碎了的回忆
    2021-02-05 05:25

    function checkEncodeURI(str) {
     return /\%/i.test(str)
    }
    

    Test :

    let url1 = "https://quora.com/unanswered/I’m-looking-for-a-Freaks-And-Friends-Fox-Glitter-Face-Hinge-Wallet-for-a-Christmas-gift-I’ve-searched-for-hours-online-but-no-one-seemed-to-have-it-does-anyone-know-where-I-can-find-one"
    let url2 = 'https://www.quora.com/unanswered/I%E2%80%99m-looking-for-a-Freaks-And-Friends-Fox-Glitter-Face-Hinge-Wallet-for-a-Christmas-gift-I%E2%80%99ve-searched-for-hours-online-but-no-one-seemed-to-have-it-does-anyone-know-where-I-can-find-one'
    let a = checkEncodeURI(url1)
    console.log(a)
    let b = checkEncodeURI(url2)
    console.log(b)
    

提交回复
热议问题