From a4bd9a1d855b126999c6fa0c341540d212f76e75 Mon Sep 17 00:00:00 2001 From: "mkaply@us.ibm.com" Date: Wed, 16 Jan 2008 11:19:21 -0800 Subject: [PATCH] 402871 - r=sayre, a=schrep - handle cases where an include is specified, but it doesn't exist --- toolkit/components/microformats/src/Microformats.js | 12 ++++++++---- .../microformats/tests/test_Microformats_hCard.html | 11 +++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/toolkit/components/microformats/src/Microformats.js b/toolkit/components/microformats/src/Microformats.js index 5e597adde6f3..c14c387e8a1b 100644 --- a/toolkit/components/microformats/src/Microformats.js +++ b/toolkit/components/microformats/src/Microformats.js @@ -703,16 +703,20 @@ var Microformats = { if (includes[i].nodeName.toLowerCase() == "object") { includeId = includes[i].getAttribute("data").substr(1); } - includes[i].parentNode.replaceChild(in_mfnode.ownerDocument.getElementById(includeId).cloneNode(true), includes[i]); + if (in_mfnode.ownerDocument.getElementById(includeId)) { + includes[i].parentNode.replaceChild(in_mfnode.ownerDocument.getElementById(includeId).cloneNode(true), includes[i]); + } } } else { var headers = in_mfnode.getAttribute("headers").split(" "); for (let i = 0; i < headers.length; i++) { var tempNode = in_mfnode.ownerDocument.createElement("span"); var headerNode = in_mfnode.ownerDocument.getElementById(headers[i]); - tempNode.innerHTML = headerNode.innerHTML; - tempNode.className = headerNode.className; - mfnode.appendChild(tempNode); + if (headerNode) { + tempNode.innerHTML = headerNode.innerHTML; + tempNode.className = headerNode.className; + mfnode.appendChild(tempNode); + } } } } else { diff --git a/toolkit/components/microformats/tests/test_Microformats_hCard.html b/toolkit/components/microformats/tests/test_Microformats_hCard.html index 7e5af3995aa8..6316747ce183 100644 --- a/toolkit/components/microformats/tests/test_Microformats_hCard.html +++ b/toolkit/components/microformats/tests/test_Microformats_hCard.html @@ -399,6 +399,10 @@ +
+ Brian Suda + +
@@ -958,6 +962,13 @@ function test_hCard() { is(hcard.email[0].value, "correct@example.com", "31-include.3 - email"); isnot(hcard.email[0].value, "incorrect@example.com", "31-include.3 - email"); + hcard = new hCard(document.getElementById("31-include.4")); + + is(hcard.fn, "Brian Suda", "31-include.3 - fn"); + is(hcard.n["given-name"], "Brian", "31-include.3 - given-name"); + is(hcard.n["family-name"], "Suda", "31-include.3 - family-name"); + is(hcard.url, "http://suda.co.uk/", "31-include.3 - url"); + hcard = new hCard(document.getElementById("32-header.1")); is(hcard.fn, "Brian Suda", "32-header.1 - fn");