Bug 1188613 - Handle attribute mutations with null value. r=pbrosset a=ritu
authorJ. Ryan Stinnett <jryans@gmail.com>
Wed, 12 Aug 2015 08:38:31 -0500
changeset 291467 3559692133bf8a4a7e29b7efb8b836d2da76d139
parent 291466 9fe71b0975bb1d9b01ee037ebb87c7e45f322074
child 291468 a111475912dcdea33675f69e9514cfee4e3acc97
push id5246
push usermozilla@noorenberghe.ca
push dateWed, 09 Sep 2015 21:17:14 +0000
reviewerspbrosset, ritu
bugs1188613
milestone41.0
Bug 1188613 - Handle attribute mutations with null value. r=pbrosset a=ritu
browser/devtools/markupview/markup-view.js
--- a/browser/devtools/markupview/markup-view.js
+++ b/browser/devtools/markupview/markup-view.js
@@ -2698,21 +2698,20 @@ ElementEditor.prototype = {
     let attributes = this.node.attributes.filter(({name}) => name !== aAttr.name);
     attributes.push(aAttr);
     let parsedLinksData = parseAttribute(this.node.namespaceURI,
       this.node.tagName, attributes, aAttr.name);
 
     // Create links in the attribute value, and collapse long attributes if
     // needed.
     let collapse = value => {
-      if (value.match(COLLAPSE_DATA_URL_REGEX)) {
+      if (value && value.match(COLLAPSE_DATA_URL_REGEX)) {
         return truncateString(value, COLLAPSE_DATA_URL_LENGTH);
-      } else {
-        return truncateString(value, COLLAPSE_ATTRIBUTE_LENGTH);
       }
+      return truncateString(value, COLLAPSE_ATTRIBUTE_LENGTH);
     };
 
     val.innerHTML = "";
     for (let token of parsedLinksData) {
       if (token.type === "string") {
         val.appendChild(this.doc.createTextNode(collapse(token.value)));
       } else {
         let link = this.doc.createElement("span");
@@ -2880,17 +2879,17 @@ ElementEditor.prototype = {
 };
 
 function nodeDocument(node) {
   return node.ownerDocument ||
     (node.nodeType == Ci.nsIDOMNode.DOCUMENT_NODE ? node : null);
 }
 
 function truncateString(str, maxLength) {
-  if (str.length <= maxLength) {
+  if (!str || str.length <= maxLength) {
     return str;
   }
 
   return str.substring(0, Math.ceil(maxLength / 2)) +
          "…" +
          str.substring(str.length - Math.floor(maxLength / 2));
 }