Last active
October 16, 2024 07:40
-
-
Save gwobcke/2773779 to your computer and use it in GitHub Desktop.
ASP seems to lack a URL Decode function but has a URL Encode function available. Here is a function that can decode any URL Encoded URL or variable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
FUNCTION URLDecoder(str) | |
'// This function: | |
'// - decodes any utf-8 encoded characters into unicode characters eg. (%C3%A5 = å) | |
'// - replaces any plus sign separators with a space character | |
'// | |
'// IMPORTANT: | |
'// Your webpage must use the UTF-8 character set. Easiest method is to use this META tag: | |
'// <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
'// | |
Dim objScript | |
Set objScript = Server.CreateObject("ScriptControl") | |
objScript.Language = "JavaScript" | |
URLDecoder = objScript.Eval("decodeURIComponent(""" & str & """.replace(/\+/g,"" ""))") | |
Set objScript = NOTHING | |
END FUNCTION | |
%> |
many thanks. it's simple and helpful.
Thanks from 2012 :) I'm surprised that Classic ASP doesn't have URL decoding.
🤌🤌🤌🤌🤌
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function is great and simple and it really helped me in solving an issue I had with URL encoding.
But I do have one important note about it:
The name of the function should be change from URLDecode, as this is a built-in function in Classic ASP and unfortunately, there is no way to override an existing function (like in JavaScript, C and so on).
I would slightly change it to URLDecoder and that would easily solve the problem described here.
(*) Don't forget to change this name also inside the function (the return value)!