Bug in IIS 5.1 JScript - undefined strings from Request object

Discussion in 'ASP General' started by Robert Mark Bram, Oct 17, 2003.

  1. Hi All!

    I have checked Windows Script help for the Undefined Data Type. It says I
    should be able to do this:
    // This method will work
    if (typeof(x) == "undefined")
    // do something

    However, I have found that when I try to get something from Session and
    Request that does not exist, the object coming back from each is different
    when they should both be undefined.

    My simple test:

    <%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
    <html>
    <body>
    reallyNotThere: &quot;<%= Session("reallyNotThere") %>&quot;<br>
    reallyNotThere2: &quot;<%= Request("reallyNotThere2") %>&quot;<br>
    <%
    var reallyNotThere = Session ("reallyNotThere");
    Response.Write("<br>Not there &quot;" + reallyNotThere + "&quot;")
    if (typeof(reallyNotThere) == "undefined")
    {
    Response.Write("<br>it is not there!");
    }
    else
    {
    Response.Write("<br>it is there");
    }

    var reallyNotThere2 = Request("reallyNotThere2");
    Response.Write("<br>Not there 2 &quot;" + reallyNotThere2 +
    "&quot;")
    if (typeof(reallyNotThere2) == "undefined")
    {
    Response.Write("<br>it is not there!");
    }
    else
    {
    Response.Write("<br>it is there");
    }
    %>
    </body>
    </html>


    The output:

    reallyNotThere: ""
    reallyNotThere2: ""

    Not there "undefined"
    it is not there!
    Not there 2 "undefined"
    it is there



    If
    (typeof(reallyNotThere) == "undefined")
    is true, so should
    (typeof(reallyNotThere2) == "undefined")

    Rob
    :)
    Robert Mark Bram, Oct 17, 2003
    #1
    1. Advertising

  2. Robert Mark Bram

    W d'Anjos Guest

    I think the difference is that Session("reallyNotThere") returns null
    and Request("reallyNotThere2") returns an empty string.

    Try Response.Write(typeof(reallyNotThere) + " - " +
    typeof(reallyNotThere2)), if I am correct it should display "undefined
    - object".

    -Wagner

    "Robert Mark Bram" <> wrote in message news:<3f8fd73a$0$24674$>...
    > Hi All!
    >
    > I have checked Windows Script help for the Undefined Data Type. It says I
    > should be able to do this:
    > // This method will work
    > if (typeof(x) == "undefined")
    > // do something
    >
    > However, I have found that when I try to get something from Session and
    > Request that does not exist, the object coming back from each is different
    > when they should both be undefined.
    >
    > My simple test:
    >
    > <%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
    > <html>
    > <body>
    > reallyNotThere: &quot;<%= Session("reallyNotThere") %>&quot;<br>
    > reallyNotThere2: &quot;<%= Request("reallyNotThere2") %>&quot;<br>
    > <%
    > var reallyNotThere = Session ("reallyNotThere");
    > Response.Write("<br>Not there &quot;" + reallyNotThere + "&quot;")
    > if (typeof(reallyNotThere) == "undefined")
    > {
    > Response.Write("<br>it is not there!");
    > }
    > else
    > {
    > Response.Write("<br>it is there");
    > }
    >
    > var reallyNotThere2 = Request("reallyNotThere2");
    > Response.Write("<br>Not there 2 &quot;" + reallyNotThere2 +
    > "&quot;")
    > if (typeof(reallyNotThere2) == "undefined")
    > {
    > Response.Write("<br>it is not there!");
    > }
    > else
    > {
    > Response.Write("<br>it is there");
    > }
    > %>
    > </body>
    > </html>
    >
    >
    > The output:
    >
    > reallyNotThere: ""
    > reallyNotThere2: ""
    >
    > Not there "undefined"
    > it is not there!
    > Not there 2 "undefined"
    > it is there
    >
    >
    >
    > If
    > (typeof(reallyNotThere) == "undefined")
    > is true, so should
    > (typeof(reallyNotThere2) == "undefined")
    >
    > Rob
    > :)
    W d'Anjos, Oct 17, 2003
    #2
    1. Advertising

  3. Hi Wagner,

    > I think the difference is that Session("reallyNotThere") returns null
    > and Request("reallyNotThere2") returns an empty string.
    >
    > Try Response.Write(typeof(reallyNotThere) + " - " +
    > typeof(reallyNotThere2)), if I am correct it should display "undefined
    > - object".


    Not quite - reallyNotThere2 is an object (with no toString method!) that
    becomes the String "undefined" when you put in a String.

    It seems an impossible test - it doesn't report itself as being null or
    undefined plus it's not an empty String.. meaning there is no easy way to
    tell whether it is "undefined" because it's not defined or "undefined"
    because the user typed that... except if you test for this:
    if ("toString" in reallyNotThere2)

    I tried this:

    var reallyNotThere = Session("reallyNotThere") ;
    var reallyNotThere2 = Request("reallyNotThere") ;

    Response.Write("=========<br>"),
    Response.Write("reallyNotThere== null - " + (reallyNotThere == null ) +
    "<br>");
    Response.Write("reallyNotThere === null - " + (reallyNotThere === null ) +
    "<br>");
    Response.Write("reallyNotThere2 == \"\" - " + (reallyNotThere2 == "" ) +
    "<br>");
    Response.Write("reallyNotThere2 === \"\" - " + (reallyNotThere2 === "" ) +
    "<br>");
    Response.Write("reallyNotThere2 == null - " + (reallyNotThere2 == null ) +
    "<br>");
    Response.Write("reallyNotThere2 === null - " + (reallyNotThere2 === null )
    + "<br>");
    Response.Write(typeof(reallyNotThere) + " - " + typeof(reallyNotThere2)+
    "<br>"),
    Response.Write("reallyNotThere is \"" + reallyNotThere + "\" - " +
    "reallyNotThere2 is \"" + reallyNotThere2 + "\"<br>");
    if ("toString" in reallyNotThere2) {
    Response.Write("reallyNotThere2 has a toString<br>");
    } else {
    Response.Write("reallyNotThere2 has no toString<br>");
    }
    Response.Write("=========<br>");




    Output:
    =========
    reallyNotThere== null - true
    reallyNotThere === null - false
    reallyNotThere2 == "" - false
    reallyNotThere2 === "" - false
    reallyNotThere2 == null - false
    reallyNotThere2 === null - false
    undefined - object
    reallyNotThere is "undefined" - reallyNotThere2 is "undefined"
    reallyNotThere2 has no toString
    =========

    Rob
    :)
    Robert Mark Bram, Oct 17, 2003
    #3
  4. On Sat, 18 Oct 2003 07:45:05 +1000, "Robert Mark Bram"
    <> wrote:

    >Hi Wagner,
    >
    >> I think the difference is that Session("reallyNotThere") returns null
    >> and Request("reallyNotThere2") returns an empty string.
    >>
    >> Try Response.Write(typeof(reallyNotThere) + " - " +
    >> typeof(reallyNotThere2)), if I am correct it should display "undefined
    >> - object".

    >
    >Not quite - reallyNotThere2 is an object (with no toString method!) that
    >becomes the String "undefined" when you put in a String.
    >
    >It seems an impossible test - it doesn't report itself as being null or
    >undefined plus it's not an empty String.. meaning there is no easy way to
    >tell whether it is "undefined" because it's not defined or "undefined"
    >because the user typed that... except if you test for this:
    >if ("toString" in reallyNotThere2)
    >
    >I tried this:
    >
    > var reallyNotThere = Session("reallyNotThere") ;
    > var reallyNotThere2 = Request("reallyNotThere") ;


    I usually do this:
    var reallyNotThere2 = String(Request("reallyNotThere"));
    if (reallyNotThere2 == "" || reallyNotThere2 == "undefined")
    reallyNotThere2 = null;
    and then test for null where appropriate.

    Regards,
    Steve
    Steve van Dongen, Oct 18, 2003
    #4
  5. Hi Steve!

    > I usually do this:
    > var reallyNotThere2 = String(Request("reallyNotThere"));
    > if (reallyNotThere2 == "" || reallyNotThere2 == "undefined")
    > reallyNotThere2 = null;
    > and then test for null where appropriate.


    I don't like to use this because of the (admittedly remote) possibility that
    I have a text field where "undefined" is a possible value... but I see your
    point.

    Rob
    :)
    Robert Mark Bram, Oct 19, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Maz
    Replies:
    4
    Views:
    1,249
    Jon Maz
    Sep 9, 2004
  2. Maxwell2006
    Replies:
    5
    Views:
    2,377
    Steven Cheng[MSFT]
    Mar 7, 2006
  3. Robert Mark Bram
    Replies:
    4
    Views:
    115
    Robert Mark Bram
    Oct 19, 2003
  4. John Bentley
    Replies:
    14
    Views:
    337
    Jim Ley
    Feb 5, 2004
  5. VK
    Replies:
    4
    Views:
    347
    Thomas 'PointedEars' Lahn
    Jan 12, 2006
Loading...

Share This Page