Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  8] [ 4]  / answers: 1 / hits: 38618  / 11 Years ago, wed, july 10, 2013, 12:00:00

I am using Javascript method decodeURIComponent to decode an encoded URL. Now I am having an issue, that sometimes the URL is get encoded twice during redirection between servers, sometimes it is encoded only once.



I want to check that if the URL is still encoded after calling the method decodeURIComponent. How can I do that? Any pointer would be very helpful to me.



Update - 1



If I recursively call a method and check that if the given URL still contains %, if it contains % then decode it and call the method again; and if not return it to the caller, will that work?



Update - 2



For my case I have:



callBackUrl=http%253A%252F%252Fadbc.com%252FPOSM%252Fapp%252Fpages%252Fadf.task-flow%253Fadf.tfDoc%253D%25252FWEB-INF%25252Ftask-flows%25252Fcatalog-edit-task-flow.xml%2526adf.tfId%253Dcatalog%2526_adf.ctrl-state%253Db9akorh22_9%2526articleReference%253D10C00135%2526previousView%253Dcatalog-home%2526fromUCM%253Dtrue%2526articleType%253Dposm%2526developer%253Dcentral


Now I am taking the value of the callBackUrl in my js method, then decoding it and firing window.open() with that decoded URL. the parameters are same and it has:




  • adf.tfDoc

  • adf.tfId

  • articleReference

  • previousView

  • fromUCM

  • articleType

  • developer



Parameters into it. So I know there is no query string like value=%...



Update - 3



I have written the following method:



var decodeURLRecursively = function(url) {
if(url.indexOf('%') != -1) {
return decodeURLRecursively(decodeURIComponent(url));
}

return url;
}

More From » urlencode

 Answers
29

Repeatedly decoding until you find no % signs will work over 99% of the time. It'll work even better if you repeatedly call so long as a match for /%[0-9a-f]{2}/i can be found.



However, if I were (for some bizarre reason) to name a file 100%achieved, that would cause a problem because %ac would be decoded to ¬, causing the decode to fail. Unfortunately there's no way to detect this case.



Ideally you should know if something is encoded more than once, and optimally you shouldn't let it happen in the first place.


[#77096] Tuesday, July 9, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lucianod

Total Points: 667
Total Questions: 106
Total Answers: 92

Location: Jordan
Member since Thu, Aug 5, 2021
3 Years ago
lucianod questions
;