Skip to content

Instantly share code, notes, and snippets.

@gwobcke
Last active April 22, 2026 22:29
Show Gist options
  • Select an option

  • Save gwobcke/2773779 to your computer and use it in GitHub Desktop.

Select an option

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.
<%
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
%>
@gwobcke
Copy link
Copy Markdown
Author

gwobcke commented Apr 22, 2026

To respond to your comments:

  1. You don’t need to use eval - I just decided to go down that path because I feel it’s cleaner.

  2. 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.

  3. Using .replace(/+/g," ") is chained inside the string evaluation, meaning the replacement of “+” actually does execute before decodeURIComponent runs and safely preserves any %2B

  4. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment