Bug 662173 - DataTransfer.getData should lowercase its argument; r=enndeakin
authorTimothy Zhu <nattofriends@gmail.com>
Tue, 08 Nov 2011 11:42:53 +0000
changeset 79999 f25597d036ec0e8e7353532fcef816c08a88fcec
parent 79998 59cf0c12f97554155f60a2ddbc9cb73514c13313
child 80000 1f0be211721f812b870b4d17a51f9c291197e0db
push idunknown
push userunknown
push dateunknown
reviewersenndeakin
bugs662173
milestone10.0a1
Bug 662173 - DataTransfer.getData should lowercase its argument; r=enndeakin
content/events/src/nsDOMDataTransfer.cpp
content/events/test/test_dragstart.html
--- a/content/events/src/nsDOMDataTransfer.cpp
+++ b/content/events/src/nsDOMDataTransfer.cpp
@@ -312,17 +312,20 @@ nsDOMDataTransfer::GetData(const nsAStri
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (data) {
     nsAutoString stringdata;
     data->GetAsAString(stringdata);
 
     // for the URL type, parse out the first URI from the list. The URIs are
     // separated by newlines
-    if (aFormat.EqualsLiteral("URL")) {
+    nsAutoString lowercaseFormat;
+    nsContentUtils::ASCIIToLower(aFormat, lowercaseFormat);
+    
+    if (lowercaseFormat.EqualsLiteral("url")) {
       PRInt32 lastidx = 0, idx;
       PRInt32 length = stringdata.Length();
       while (lastidx < length) {
         idx = stringdata.FindChar('\n', lastidx);
         // lines beginning with # are comments
         if (stringdata[lastidx] == '#') {
           if (idx == -1)
             break;
@@ -825,22 +828,24 @@ nsDOMDataTransfer::GetCurrentPrincipal(n
 
   return currentPrincipal.get();
 }
 
 void
 nsDOMDataTransfer::GetRealFormat(const nsAString& aInFormat, nsAString& aOutFormat)
 {
   // treat text/unicode as equivalent to text/plain
-  if (aInFormat.EqualsLiteral("Text") || aInFormat.EqualsLiteral("text/unicode"))
+  nsAutoString lowercaseFormat;
+  nsContentUtils::ASCIIToLower(aInFormat, lowercaseFormat);
+  if (lowercaseFormat.EqualsLiteral("text") || lowercaseFormat.EqualsLiteral("text/unicode"))
     aOutFormat.AssignLiteral("text/plain");
-  else if (aInFormat.EqualsLiteral("URL"))
+  else if (lowercaseFormat.EqualsLiteral("url"))
     aOutFormat.AssignLiteral("text/uri-list");
   else
-    aOutFormat.Assign(aInFormat);
+    aOutFormat.Assign(lowercaseFormat);
 }
 
 void
 nsDOMDataTransfer::CacheExternalFormats()
 {
   // Called during the constructor to cache the formats available from an
   // external drag. The data associated with each format will be set to null.
   // This data will instead only be retrieved in FillInExternalDragData when
--- a/content/events/test/test_dragstart.html
+++ b/content/events/test/test_dragstart.html
@@ -124,16 +124,18 @@ function doDragStartSelection(event)
   is(dt.getData("text/plain"), "This is a draggable bit of text.", "initial selection text/plain");
   is(dt.getData("text/html"), "<div id=\"draggable\" ondragstart=\"doDragStartSelection(event)\">This is a <em>draggable</em> bit of text.</div>",
      "initial selection text/html");
 
   // text/unicode and Text are available for compatibility. They retrieve the
   // text/plain data
   is(dt.getData("text/unicode"), "This is a draggable bit of text.", "initial selection text/unicode");
   is(dt.getData("Text"), "This is a draggable bit of text.", "initial selection Text");
+  is(dt.getData("TEXT"), "This is a draggable bit of text.", "initial selection TEXT");
+  is(dt.getData("text/UNICODE"), "This is a draggable bit of text.", "initial selection text/UNICODE"); 
 
   is(dt.mozItemCount, 1, "initial selection item count");
 
   dt.clearData("text/plain");
   dt.clearData("text/html");
   dt.clearData("text/_moz_htmlinfo");
   dt.clearData("text/_moz_htmlcontext");