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

62
Visualizações
encodeURIComponent returning string with % on it

Why whenever I run encodeURIComponent('my_url'), I get a weird looking URL like https%3A%2F%2Fr[...]... Why is that and how do I solve it?

Btw, I'm using Windows.

function createSharedAccessToken(uri, saName, saKey) {
  uri = // '...'
  saName = // '...'
  saKey = // '...'

  if (!uri || !saName || !saKey) {
    throw "Missing required parameter";
  }
  var encoded = encodeURIComponent(uri);
  var now = new Date();
  var week = 60 * 60 * 24 * 7;
  var ttl = Math.round(now.getTime() / 1000) + week;
  var signature = encoded + '\n' + ttl;
  var signatureUTF8 = utf8.encode(signature);
  var hash = crypto.createHmac('sha256', saKey).update(signatureUTF8).digest('base64');
  return 'SharedAccessSignature sr=' + encoded + '&sig=' +
    encodeURIComponent(hash) + '&se=' + ttl + '&skn=' + saName;
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The type of 'wierd looking url' you shared is eactly what encodeURIComponent is designed to return.

all character except A-Z a-z 0-9 - _ . ! ~ * ' ( ) get replaced by escape sequences.

For example, any spaces become %20 and / becomes %2F.

A typical URL, processed by encodeURIComponent, might look like this:

https%3A%2F%2Fstackoverflow.com

When you are ready to display the original string, you simply use decodeURIComponent to reverse the process:

decodeYRIComponent('https%3A%2F%2Fstackoverflow.com');

// becomes: https://stackoverflow.com

about 4 years ago · Juan Pablo Isaza Relatório

0

It is well explained here, why we need to encode the URL

if a user writes Jack & Jill, the text may get encoded as Jack & Jill. Without encodeURIComponent() the ampersand could be interpreted on the server as the start of a new field and jeopardize the integrity of the data.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

If we need it in human readable form, we always have https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI

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