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
%>
@therbta
Copy link
Copy Markdown

therbta commented Nov 24, 2022

Thanks from 2012 :) I'm surprised that Classic ASP doesn't have URL decoding.

@badursun
Copy link
Copy Markdown

🤌🤌🤌🤌🤌

@ernix
Copy link
Copy Markdown

ernix commented Apr 20, 2026

There are a few things I'd like to point out:

  • You don't have to use Eval
  • It's JScript, not JavaScript
  • + signs must be replaced before decodeURIComponent, %2B is a valid URL encoded character.
  • Your webpage does not need to be UTF-8 encoded, It depends on how str argument was encoded.
<%
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
'//
    Dim objScript
    Dim objJS
    Set objScript = Server.CreateObject("ScriptControl")
    objScript.Language = "JScript"
    Set objJS = objScript.CodeObject
    URLDecoder = objJS.decodeURIComponent(Replace(str, "+", " "))
    Set objJS = NOTHING
    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