Last active
April 22, 2026 22:29
-
-
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 | |
| %> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To respond to your comments:
You don’t need to use eval - I just decided to go down that path because I feel it’s cleaner.
JavaScript vs JScript: While Microsoft’s underlying engine is indeed JScript, passing "JavaScript" to ScriptControl.Language is fully supported. Windows maps "JavaScript" to the exact same COM ProgID under the hood, so both names work interchangeably here without any issues.
Using .replace(/+/g," ") is chained inside the string evaluation, meaning the replacement of “+” actually does execute before decodeURIComponent runs and safely preserves any %2B
decodeURIComponent natively expects UTF-8 encoded URIs - however, note I commented practical advice for Classic ASP developers in older ASP environments like CodePage 1252. If you decode a UTF-8 string and output it to a page that isn't explicitly set to UTF-8, it will most likely render those decoded characters (like å) as garbled text (mojibake).
In conclusion there is no functional difference to your suggestion and my original GIST.