Skip to content

Latest commit

 

History

History
26 lines (23 loc) · 988 Bytes

16.md

File metadata and controls

26 lines (23 loc) · 988 Bytes

请解码被多次编码的 URL

const s = 'https://wwww.baidu.com?a=1&b=2&c=3'

let tempStr = undefined
console.log(tempStr = encodeURIComponent(s))
console.log(tempStr = encodeURIComponent(tempStr))
console.log(tempStr = encodeURIComponent(tempStr))
console.log(tempStr = encodeURIComponent(tempStr))
console.log(tempStr = encodeURIComponent(tempStr))

// https%3A%2F%2Fwwww.baidu.com%3Fa%3D1%26b%3D2%26c%3D3
// https%253A%252F%252Fwwww.baidu.com%253Fa%253D1%2526b%253D2%2526c%253D3
// https%25253A%25252F%25252Fwwww.baidu.com%25253Fa%25253D1%252526b%25253D2%252526c%25253D3
// https%2525253A%2525252F%2525252Fwwww.baidu.com%2525253Fa%2525253D1%25252526b%2525253D2%25252526c%2525253D3
// https%252525253A%252525252F%252525252Fwwww.baidu.com%252525253Fa%252525253D1%2525252526b%252525253D2%2525252526c%252525253D3
function decodeUrlInfinity(url) {
  const str = decodeURIComponent(url)
  if (str === url) {
    return url
  } else {
    return decodeUrlInfinity(str)
  }
}