<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>7104</bug_id>
          
          <creation_ts>2009-07-14 19:41:46 +0000</creation_ts>
          <short_desc>Disagreement on handling of null value for localStorage.setItem()</short_desc>
          <delta_ts>2009-08-09 23:12:35 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>Web Storage (editor: Ian Hickson)</component>
          <version>unspecified</version>
          <rep_platform>Macintosh</rep_platform>
          <op_sys>MacOS X</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Brett C.">brett</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>ian</cc>
    
    <cc>jorlow</cc>
    
    <cc>mike</cc>
    
    <cc>public-webapps</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>25963</commentid>
    <comment_count>0</comment_count>
      <attachid>718</attachid>
    <who name="Brett C.">brett</who>
    <bug_when>2009-07-14 19:41:46 +0000</bug_when>
    <thetext>Created attachment 718
test page that shows what localStorage.getItem() thinks null should be

In Safari 4, if you use null as a value when setting a new key it will end up returning the string &quot;null&quot;. But in Firefox 3.5, you get back null itself. I have attached a dead-simple HTML file that shows the differences when run in the two browsers. Not sure who is right since the spec says a DOMString is expected and I am not sure if null is considered a valid DOMString.

And in both browsers you end up with a key being set. While in Safari that makes sense since you are getting back a string, but in Firefox that&apos;s confusing as the value for the key is the same as the value used to signify that no value exists for the key. That means in Firefox the only way to know  that the key is actually set explicitly to null is to iterate through all the keys using localStorage.key() to try to see if the key has actually been given a value.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>25967</commentid>
    <comment_count>1</comment_count>
    <who name="Jeremy Orlow">jorlow</who>
    <bug_when>2009-07-15 02:03:13 +0000</bug_when>
    <thetext>I brought this up on WhatWG a while ago.  I believe it was agreed that Firefox&apos;s implementation goes against the spec.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>25968</commentid>
    <comment_count>2</comment_count>
    <who name="Brett C.">brett</who>
    <bug_when>2009-07-15 04:36:07 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; I brought this up on WhatWG a while ago.  I believe it was agreed that
&gt; Firefox&apos;s implementation goes against the spec.
&gt; 

Best I could find was http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2008-April/014383.html which ended with someone believing that Firefox is wrong and Safari is right, but no definitive answer.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>25970</commentid>
    <comment_count>3</comment_count>
    <who name="Jeremy Orlow">jorlow</who>
    <bug_when>2009-07-15 07:21:19 +0000</bug_when>
    <thetext>I apologize...I must have been remembering incorrectly.  I couldn&apos;t even find any mentions of any such message in my email archive, which further confounds me.

So yes, I suppose it is good to double check and perhaps have specific language in the spec to settle the issue once and for all.  :-)

From my reading, the Safari way of doing things is definitely the correct one.  The rational is essentially what you already mentioned, Brett.

If not, a .contains method should be added...but writing code for such an interface seems cumbersome.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>25981</commentid>
    <comment_count>4</comment_count>
    <who name="Brett C.">brett</who>
    <bug_when>2009-07-15 18:34:26 +0000</bug_when>
    <thetext>Although my opinion counts for squat, I do agree with Safari&apos;s behavior as well. Coercion of an object to a string is common enough in JS that it is reasonable to have null coerced. It did catch me by surprise that it did that, but I chalk that up to lack of JS experience on my part.

And once an official decision is made on this I will report the proper behavior to the right browser folks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>26332</commentid>
    <comment_count>5</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2009-08-09 22:04:35 +0000</bug_when>
    <thetext>I propose to make the spec just use the default behaviour specified by Web IDL.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>26336</commentid>
    <comment_count>6</comment_count>
    <who name="Brett C.">brett</who>
    <bug_when>2009-08-09 22:57:55 +0000</bug_when>
    <thetext>Could you tell me what that means, Ian? I am writing a localStorage wrapper to deal with browser incompatibilities and add some helper functions and I would like to keep the wrapper agreeing with the spec.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>26337</commentid>
    <comment_count>7</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2009-08-09 23:05:30 +0000</bug_when>
    <thetext>I&apos;m not 100% sure, as this has changed a few times, but it appears:
   http://dev.w3.org/2006/webapi/WebIDL/#TreatNullAs
...that it means that null and undefined, when passed to methods accepting DOMStrings, treat them as the strings &quot;null&quot; and &quot;undefined&quot; respectively.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>26341</commentid>
    <comment_count>8</comment_count>
    <who name="Brett C.">brett</who>
    <bug_when>2009-08-09 23:12:35 +0000</bug_when>
    <thetext>Thanks for the clarification, Ian! That&apos;s what I figured; just pass all key/value arguments through String. That leaves Firefox 3.5 incompatible in this instance and (I believe) a bug report has been sent in.

And as an aside for anyone curious how FF 3.5 and Safari 4 are incompatible with the spec so far, both do not implement ``localStorage.key(localStorage.length)`` properly as they both throw an exception instead of returning null. I reported the appropriate bugs. Otherwise they seem to be following the spec.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>718</attachid>
            <date>2009-07-14 19:41:46 +0000</date>
            <delta_ts>2009-07-14 19:41:46 +0000</delta_ts>
            <desc>test page that shows what localStorage.getItem() thinks null should be</desc>
            <filename>web_storage.html</filename>
            <type>text/html</type>
            <size>701</size>
            <attacher name="Brett C.">brett</attacher>
            
              <data encoding="base64">PGh0bWw+Cjxib2R5PgogICAgPHA+c2V0SXRlbSB3aXRoIG51bGw6ICI8c3BhbiBpZD0idXNlLW51
bGwiPlhYWDwvc3Bhbj4iICh0eXBlb2YgPHNwYW4KICAgICAgICBpZD0idmFsdWUtdHlwZSI+WFhY
PC9zcGFuPik8L3A+CiAgICA8cD5OdWxsIGNyZWF0ZXMgYSBrZXkgZW50cnk/IDxzcGFuIGlkPSJu
ZXcta2V5Ij5YWFg8c3Bhbj48L3A+CjxzY3JpcHQgdHlwZT0idGV4dC9qYXZhc2NyaXB0Ij4KICAg
IGxvY2FsU3RvcmFnZS5jbGVhcigpOwogICAgdmFyIGtleSA9ICJ0ZXN0IGtleSI7CiAgICBsb2Nh
bFN0b3JhZ2Uuc2V0SXRlbShrZXksIG51bGwpOwogICAgdmFyIG51bGxfcmVwb3J0ID0gZG9jdW1l
bnQuZ2V0RWxlbWVudEJ5SWQoInVzZS1udWxsIik7CiAgICB2YXIgdmFsdWUgPSBsb2NhbFN0b3Jh
Z2UuZ2V0SXRlbShrZXkpOwogICAgbnVsbF9yZXBvcnQuaW5uZXJIVE1MID0gdmFsdWU7CiAgICB2
YXIgdHlwZW9mX3JlcG9ydCA9IGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJ2YWx1ZS10eXBlIik7
CiAgICB0eXBlb2ZfcmVwb3J0LmlubmVySFRNTCA9IHR5cGVvZiB2YWx1ZTsKICAgIHZhciBrZXlf
Y291bnRfcmVwb3J0ID0gZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoIm5ldy1rZXkiKTsKICAgIGtl
eV9jb3VudF9yZXBvcnQuaW5uZXJIVE1MID0gbG9jYWxTdG9yYWdlLmtleSgwKTsKPC9zY3JpcHQ+
CjwvYm9keT4KPC9odG1sPgo=
</data>

          </attachment>
      

    </bug>

</bugzilla>