Loading ...
Sorry, an error occurred while loading the content.

Re: Problem with YAHOO.util.Cookie.setSub

Expand Messages
  • ticklishturtletoe
    Hi Nicholas, I m not trying to argue with you, so please don t take my reply negatively. I m only describing what I see. While my exposure to YUI is limited,
    Message 1 of 5 , Jun 2, 2008
    • 0 Attachment
      Hi Nicholas,

      I'm not trying to argue with you, so please don't take my reply
      negatively. I'm only describing what I see. While my exposure to YUI
      is limited, I've been a software developer (C++, Java, etc) for 10 years.

      My understanding of getSubs is correct. It's a very small function and
      simple to understand. When I step through that code using Firebug, it
      clearly returns null when the cookie doesn't yet exist (see line 256
      of version 2.5.1 of cookie-beta-debug.js).

      So when line 345 and following is executed, hash has a null value:

      if (!lang.isObject(hash)){
      hash = new Object();
      }

      Problem is, isObject in version 2.5.1 didn't check for a null object:

      isObject:function(obj){
      return typeof obj=='object'||YAHOO.lang.isFunction(obj);
      }

      But version 2.5.2 corrects that problem:

      isObject: function(o) {
      return (o && (typeof o === 'object' || L.isFunction(o))) || false;
      }

      I haven't checked when 2.5.2 was released, but my code now works
      because of that one fix in the isObject function.

      I appreciate your willingness to look into my problem.

      Kind Regards,
      TTT

      --- In ydn-javascript@yahoogroups.com, "Nicholas Zakas" <nzakas@...>
      wrote:
      >
      > Hi TTT,
      >
      >
      >
      > Your interpretation of the code is close to correct, although the call
      > to getSubs() doesn't assume that the cookie with the given name exists.
      > In fact, it is checking to see if a cookie with the given name exists.
      > If it does, then getSubs() returns an object that must be added to; if
      > it does not, then a new object is created.
      >
      >
      >
      > The call to YAHOO.lang.isObject() also does a check for null. If you run
      > YAHOO.lang.isObject(null), the result is false, so the very test that
      > you're suggesting is, in fact, already taking place.
      >
      >
      >
      > If you take a look in the YUI downloadable ZIP file, there is a
      > directory called "tests". In that directory, there is a file called
      > cookie.html that contains unit tests for the Cookie utility. There are
      > numerous unit tests in that file specifically for the subcookie
      > functionality. If you run those tests, you should see everything pass.
      > There is a test called testSetSubSimple that tests the very case that
      > you're describing. If that passes, it means that it's probably something
      > you're doing in your use of setSub() that is the problem. If the fails,
      > then that means there's a bug somewhere in the cookie code.
      >
      >
      >
      > I hope this helps. If you continue to have issues, please paste your
      > code into your next email so I can take a look.
      >
      >
      >
      > Thanks,
      >
      > Nicholas
      >
      >
      >
      > ________________________________
      >
      > From: ydn-javascript@yahoogroups.com
      > [mailto:ydn-javascript@yahoogroups.com] On Behalf Of ticklishturtletoe
      > Sent: Tuesday, May 20, 2008 10:32 AM
      > To: ydn-javascript@yahoogroups.com
      > Subject: [ydn-javascript] Re: Problem with YAHOO.util.Cookie.setSub
      >
      >
      >
      > Hi Nicholas,
      >
      > I appreciate your reply. The cookie name doesn't exist yet. I'm
      > certain of that. The trouble is, the call to
      > YAHOO.util.Cookie.setSub() actually fails *because* the cookie doesn't
      > exist yet.
      >
      > Here's a snippet from setSub from the cookie-beta-debug.js:
      >
      > var hash /*:Object*/ = this.getSubs(name);
      >
      > if (!lang.isObject(hash)){
      > hash = new Object();
      > }
      >
      > hash[subName] = value;
      >
      > The call to getSubs(name) shows that there's an expectation that the
      > cookie should already exist, because, if it's null, then hash is null,
      > which causes the !lang.isObject(hash) test to fail. And attempts to
      > assign a value to hash[subName] will fail. It seems to me that the if
      > statement should be:
      >
      > if (hash == null || !lang.isObject(hash))
      >
      > I could be wrong, but that's how it looks to me.
      >
      > Kind Regards,
      > TTT
      >
      > --- In ydn-javascript@yahoogroups.com
      > <mailto:ydn-javascript%40yahoogroups.com> , "Nicholas Zakas"
      > <nzakas@>
      > wrote:
      > >
      > > Hi TTT,
      > >
      > >
      > >
      > > The call to YAHOO.lang.isObject() only returns true if the value is an
      > > object and also isn't null. My hunch is that there's a cookie of the
      > > same name that already exists but can't be parsed as containing
      > > subcookies. Please try clearing all of your cookies and trying the
      > code
      > > again. If you're still having issues after that, take a look at the
      > > value of document.cookie to see if a cookie of the same name already
      > > exists. If you're not sure, please paste your complete code to the
      > list
      > > and I can take a look.
      > >
      > >
      > >
      > > Thanks,
      > >
      > > Nicholas
      > >
      > >
      > >
      > > ________________________________
      > >
      > > From: ydn-javascript@yahoogroups.com
      > <mailto:ydn-javascript%40yahoogroups.com>
      > > [mailto:ydn-javascript@yahoogroups.com
      > <mailto:ydn-javascript%40yahoogroups.com> ] On Behalf Of
      > ticklishturtletoe
      > > Sent: Tuesday, May 20, 2008 7:17 AM
      > > To: ydn-javascript@yahoogroups.com
      > <mailto:ydn-javascript%40yahoogroups.com>
      > > Subject: [ydn-javascript] Problem with YAHOO.util.Cookie.setSub
      > >
      > >
      > >
      > > Hi all,
      > >
      > > I've been getting lots of great use out of the Yahoo UI library!
      > > Congrats to the development team and the community for making it a
      > > wonderful tool for web development!
      > >
      > > I'm trying to create an initial sub-cookie but I'm running into
      > > trouble. It seems that it fails on the !isObject test (line 345 in
      > > cookie-beta-debug.js), which should return true, since the hash hasn't
      > > yet been initialized. Perhaps that test should be amended to also test
      > > for null?
      > >
      > > Thanks in advance for your input!
      > >
      > > TTT
      > >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.