0

I want to make a function that removes the "()" from the url: https://salgadofilho.pr.gov.br/uploads/noticia/copel_(244).jpg

so that it continues to work, I've tried to use the function below but it returns this https%3A%2F%2Fsalgadofilho.pr.gov.br%2Fuploads%2Fnoticia%2Fcopel_(244).jpg

function urlEncode(url) {
  const urlDec = encodeURIComponent(url)
  return console.log(urlDec)
}


urlEncode('https://salgadofilho.pr.gov.br/uploads/noticia/copel_(244).jpg')

and does not remove the "()", there is no way to remove it with JS method because the url is not found. does anyone know how to do it?

1 Answers1

0

You don't actually need to encode parenthesis, unless you need to be RFC3986 compliant, in which case you can use the code from this answer to the same question.

function fixedEncodeURIComponent(str) {
  return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
    return '%' + c.charCodeAt(0).toString(16);
  });
}
Ethan R
  • 338
  • 2
  • 9