SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ATTN: Undocumented VBS functions!!!

    I was astounded to discover today that the VBS engine contains some functions which are undocumented!

    So far, I am only aware of Escape() and UnEscape(), which are available in the JScript runtime but not in VBScript (or so everyone thought). These are handy in client-side JS, so might come in handy for server-side processing. There are many custom scripts floating about the 'net which implement these functions, but it's always nice to use built-in functions if they exist, and "lo and behold" they do!

    I found this information buried in the depths of MSDN here. Beware of their limited use though (the colon example being an example).

    Try this:
    Code:
    <%
    'used to display results in the browser without
    'the browser interpreting any of the HTML
    Sub DisplayString(label,str)
    	response.write "<b>" & label & "</b>: " & server.HTMLEncode(str) & "<HR>"
    End Sub
    
    s = "<xsd:element name='Order'> lots of stuff...! me@here.com"
    esc = escape(s)
    unesc = unescape(esc)
    enc = server.URLEncode(s)
    
    DisplayString "Original string",s
    DisplayString "Escaped",esc
    DisplayString "Unescaped",unesc
    DisplayString "URLEncoded",enc
    %>
    (the Server.URLEncode is there to demonstrate the fact that it is different to escaping)

    Does anybody know of any other undocumented VBScript features? I am already aware of the Response object's undocumented .WriteBlock() method - see here for more info if you're interested...!


    M@rco

  2. #2
    I'm NOT an Addict ! TheRock's Avatar
    Join Date
    Jul 2001
    Location
    Earth ... maybe
    Posts
    401
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: ATTN: Undocumented VBS functions!!!

    Originally posted by M@rco
    I was astounded to discover today that the VBS engine contains some functions which are undocumented!

    I found this information buried in the depths of MSDN here.
    Still you call it undocumented?
    -*-
    B-School Forums - GMAT / MBA / Admissions discussions
    -*-

  3. #3
    Guru Bullschmidt's Avatar
    Join Date
    Apr 2002
    Location
    USA
    Posts
    524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    M@rco,

    What you wrote sounds interesting and I THOUGHT I understood it to mean that one can escape a string which we already do with Server.URLEncode but now we had a change to unescape it to see what it looked like instead of having to just user Request.QueryString() on the actual new page.

    But then you wrote:
    (the Server.URLEncode is there to demonstrate the fact that it is different to escaping)
    So my questions are:
    1) What IS the difference between Server.URLEncode and escaping?
    2) What is an example use of these "undocumented" functions? (I.e. what are they good for in terms of a practical use?)
    J. Paul Schmidt
    www.Bullschmidt.com - Freelance Web and Database Developer
    www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips

  4. #4
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The URLEncode and escape seem to encode it differently:
    [vbs]
    Original string: <xsd:element name='Order'> lots of stuff...! me@here.com
    --------------------------------------------------------------------------------
    Escaped: %3Cxsd%3Aelement%20name%3D%27Order%27%3E%20lots%20of%20stuff...%21%20me@here.com
    --------------------------------------------------------------------------------
    Unescaped: <xsd:element name='Order'> lots of stuff...! me@here.com
    --------------------------------------------------------------------------------
    URLEncoded: %3Cxsd%3Aelement+name%3D%27Order%27%3E+lots+of+stuff%2E%2E%2E%21+me%40here%2Ecom
    [/vbs]
    As you can see the escape leaves the periods and @ sign untouched and format the spaces as %20 instead of +...

    The actual pratical use of this? I can't really think ay except maybe a different way to pass string over with querystring.

  5. #5
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've never used them myself, but had assumed that others did use them because of the existence of VBS scripts which people have written to implement this functionality.

    I've done a little research, and it seems that MS has implemented the same functionality as Netscape's JS escape() and unescape() functions, and therefore share the same problems, which you have pointed out.

    Some stuff here and here if you're interested.

    Server.URLEncode would appear to be a superior version of Escape() which is designed to overcome these limitations.

    Microsoft's JScript engine actually DOES support proper URL encoding and decoding via the encodeURI, encodeURIComponent, decodeURI, and decodeURIComponent methods, but unfortunately these are not present in VBS (not even as undocumented features).

    Since there is no built-in VBS URLDecode function to convert it back, (and as we know, the Unescape() function is flawed) I have written a URLDecode() function which uses Unescape() to do most of the work, and then corrects the remaining characters with multiple replaces:
    Code:
    <%
    Function URLDecode(str)
    str = unescape(str)
    str = replace(str,"+"," ")
    str = replace(str,"%2A","*")
    str = replace(str,"%40","@")
    str = replace(str,"%2D","-")
    str = replace(str,"%5F","_")
    str = replace(str,"%2B","+")
    str = replace(str,"%2E",".")
    str = replace(str,"%2F","/")
    URLDecode = str
    End Function
    %>

    M@rco

  6. #6
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to clarify, there is no need to use the escape() or unescape() at all now - just use Server.URLEncode and my URLDecode function to manipulate your URL strings.


    M@rco

  7. #7
    Guru Bullschmidt's Avatar
    Join Date
    Apr 2002
    Location
    USA
    Posts
    524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have written a URLDecode() function which uses Unescape() to do most of the work, and then corrects the remaining characters with multiple replaces:
    Way to go, I always thought there should be an URLDecode() function...
    J. Paul Schmidt
    www.Bullschmidt.com - Freelance Web and Database Developer
    www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips

  8. #8
    Rehab is for quiters! spartan's Avatar
    Join Date
    Apr 2002
    Location
    Cape Town, South Africa
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice one M@rco, nI am using it as we speak...
    Spartan
    ---------------------
    It's like our sergeant told us before one trip into the jungle. Men! Fifty of you are leaving on a mission. Twenty-five of you ain't coming back.
    -Mr.Payne

  9. #9
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad it's come in handy for you guys!
    Add it to your code libraries!


    M@rco


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •