Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
Should we enclose filename with encodeURIComponent in Javascript?

I'm accepting files to be uploaded to my site. So, is it a safe practice to encodeURIComponent the filename? Or should I use escape()? OR is it necessary at all?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You should never use escape for anything (unless forced to because you're sending information to something that will use unescape [which it shouldn't]).

Whether you need to use encodeURIComponent depends entirely on whether you're going to use the filename directly as a URI component¹. If you are, yes, you should use it. If you aren't, no, you probably shouldn't.


¹ for instance, as a query string parameter when you're creating the query string manually rather than via URLSearchParams (which is generally better practice)

about 4 years ago · Juan Pablo Isaza Relatório

0

encodeURIComponent takes a string and escapes it to make it safe to insert into a URI, typically used for query string data.

If you are inserting a string into a URI then you can use it, but should probably use URLSearchParams to construct the whole query string instead.

If you aren't inserting a string into a URI then you probably should not use it.


escape is deprecated and should not be used. It doesn't work property with Unicode.


Considerations for accepting files are typically more along the lines of "Will this accidentally overwrite an existing file?" and "Are the characters in this filename allowed by my filesystem?".

Some people prefer to generate a completely new file name (e.g. with a guid library) to ensure it is safe. You could store the original name in a database (at which point your escaping should be handled by parametrised queries).

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda