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

208
Views
request.getParameter returns dirty string

I have a site which is made by a CMS. When the site is visited as normal and a user search on the site with the URL:

https://test.se/test.html?language=sv&SubjectArea=Ekonomi&identity=programSV,coursesSV,lifeLongLearningCoursesSV&showbutton=false

The JS code:

let test = requester.getParameter("identity") 
console.log(test)
// programSV,coursesSV,lifeLongLearningCoursesSV

returns programSV,coursesSV,lifeLongLearningCoursesSV as expected.

But when I visit the site at the exact same URL but I come from an external page JS code above returns this instead: programSV%2CcoursesSV%2ClifeLongLearningCoursesSV

Any suggestions on what could be wrong and how this could be fixed?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Use a URL search params for consistency - it will decode the URL for you regardless of encoded entities

Alternatively use decodeURIComponent

const url1 = new URL(`https://test.se/test.html?language=sv&SubjectArea=Ekonomi&identity=programSV,coursesSV,lifeLongLearningCoursesSV&showbutton=false`)

const url2 = new URL(`https://test.se/test.html?language=sv&SubjectArea=Ekonomi&identity=programSV%2CcoursesSV%2ClifeLongLearningCoursesSV&showbutton=false`)

console.log(url1.searchParams.get("identity"))

console.log(url2.searchParams.get("identity"))

// alternative

console.log(decodeURIComponent(`programSV%2CcoursesSV%2ClifeLongLearningCoursesSV`))

NOTE: decodeURI does nothing for your commas:

decodeURI(requester.getParameter("identity"))

returns programSV%2CcoursesSV%2ClifeLongLearningCoursesSV

however decodeURIComponent does work:

decodeURIComponent(requester.getParameter("identity"))

returns programSV,coursesSV,lifeLongLearningCoursesSV

about 4 years ago · Juan Pablo Isaza Report

0

the commas are being encoded, you have to use decodeURIComponent. Like this: decodeURIComponent(requester.getParameter("identity")). See link for reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent

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!