Bug in IIS 5.1 JScript - undefined strings from Request object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Mark Bram

    Bug in IIS 5.1 JScript - undefined strings from Request object

    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="JA VASCRIPT" CODEPAGE="65001 "%>
    <html>
    <body>
    reallyNotThere: &quot;<%= Session("really NotThere") %>&quot;<br>
    reallyNotThere2 : &quot;<%= Request("really NotThere2") %>&quot;<br>
    <%
    var reallyNotThere = Session ("reallyNotTher e");
    Response.Write( "<br>Not there &quot;" + reallyNotThere + "&quot;")
    if (typeof(reallyN otThere) == "undefined" )
    {
    Response.Write( "<br>it is not there!");
    }
    else
    {
    Response.Write( "<br>it is there");
    }

    var reallyNotThere2 = Request("really NotThere2");
    Response.Write( "<br>Not there 2 &quot;" + reallyNotThere2 +
    "&quot;")
    if (typeof(reallyN otThere2) == "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(reallyN otThere) == "undefined" )
    is true, so should
    (typeof(reallyN otThere2) == "undefined" )

    Rob
    :)


  • W d'Anjos

    #2
    Re: Bug in IIS 5.1 JScript - undefined strings from Request object

    I think the difference is that Session("really NotThere") returns null
    and Request("really NotThere2") returns an empty string.

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

    -Wagner

    "Robert Mark Bram" <relaxedrob@rem ovethis.optusho me.com.au> wrote in message news:<3f8fd73a$ 0$24674$afc38c8 7@news.optusnet .com.au>...[color=blue]
    > 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="JA VASCRIPT" CODEPAGE="65001 "%>
    > <html>
    > <body>
    > reallyNotThere: &quot;<%= Session("really NotThere") %>&quot;<br>
    > reallyNotThere2 : &quot;<%= Request("really NotThere2") %>&quot;<br>
    > <%
    > var reallyNotThere = Session ("reallyNotTher e");
    > Response.Write( "<br>Not there &quot;" + reallyNotThere + "&quot;")
    > if (typeof(reallyN otThere) == "undefined" )
    > {
    > Response.Write( "<br>it is not there!");
    > }
    > else
    > {
    > Response.Write( "<br>it is there");
    > }
    >
    > var reallyNotThere2 = Request("really NotThere2");
    > Response.Write( "<br>Not there 2 &quot;" + reallyNotThere2 +
    > "&quot;")
    > if (typeof(reallyN otThere2) == "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(reallyN otThere) == "undefined" )
    > is true, so should
    > (typeof(reallyN otThere2) == "undefined" )
    >
    > Rob
    > :)[/color]

    Comment

    • Robert Mark Bram

      #3
      Re: Bug in IIS 5.1 JScript - undefined strings from Request object

      Hi Wagner,
      [color=blue]
      > I think the difference is that Session("really NotThere") returns null
      > and Request("really NotThere2") returns an empty string.
      >
      > Try Response.Write( typeof(reallyNo tThere) + " - " +
      > typeof(reallyNo tThere2)), if I am correct it should display "undefined
      > - object".[/color]

      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("really NotThere") ;
      var reallyNotThere2 = Request("really NotThere") ;

      Response.Write( "=========<br>" ),
      Response.Write( "reallyNotThere == null - " + (reallyNotThere == null ) +
      "<br>");
      Response.Write( "reallyNotT here === null - " + (reallyNotThere === null ) +
      "<br>");
      Response.Write( "reallyNotThere 2 == \"\" - " + (reallyNotThere 2 == "" ) +
      "<br>");
      Response.Write( "reallyNotThere 2 === \"\" - " + (reallyNotThere 2 === "" ) +
      "<br>");
      Response.Write( "reallyNotThere 2 == null - " + (reallyNotThere 2 == null ) +
      "<br>");
      Response.Write( "reallyNotThere 2 === null - " + (reallyNotThere 2 === null )
      + "<br>");
      Response.Write( typeof(reallyNo tThere) + " - " + typeof(reallyNo tThere2)+
      "<br>"),
      Response.Write( "reallyNotT here is \"" + reallyNotThere + "\" - " +
      "reallyNotThere 2 is \"" + reallyNotThere2 + "\"<br>");
      if ("toString" in reallyNotThere2 ) {
      Response.Write( "reallyNotThere 2 has a toString<br>");
      } else {
      Response.Write( "reallyNotThere 2 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
      :)


      Comment

      • Steve van Dongen

        #4
        Re: Bug in IIS 5.1 JScript - undefined strings from Request object

        On Sat, 18 Oct 2003 07:45:05 +1000, "Robert Mark Bram"
        <relaxedrob@rem ovethis.optusho me.com.au> wrote:
        [color=blue]
        >Hi Wagner,
        >[color=green]
        >> I think the difference is that Session("really NotThere") returns null
        >> and Request("really NotThere2") returns an empty string.
        >>
        >> Try Response.Write( typeof(reallyNo tThere) + " - " +
        >> typeof(reallyNo tThere2)), if I am correct it should display "undefined
        >> - object".[/color]
        >
        >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("really NotThere") ;
        > var reallyNotThere2 = Request("really NotThere") ;[/color]

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

        Regards,
        Steve

        Comment

        • Robert Mark Bram

          #5
          Re: Bug in IIS 5.1 JScript - undefined strings from Request object

          Hi Steve!
          [color=blue]
          > I usually do this:
          > var reallyNotThere2 = String(Request( "reallyNotThere "));
          > if (reallyNotThere 2 == "" || reallyNotThere2 == "undefined" )
          > reallyNotThere2 = null;
          > and then test for null where appropriate.[/color]

          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
          :)


          Comment

          Working...