Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

61
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!