Index: src/com/google/caja/plugin/html-emitter.js |
=================================================================== |
--- src/com/google/caja/plugin/html-emitter.js (revision 3649) |
+++ src/com/google/caja/plugin/html-emitter.js (working copy) |
@@ -40,7 +40,8 @@ |
idMap = {}; |
var descs = base.getElementsByTagName('*'); |
for (var i = 0, desc; (desc = descs[i]); ++i) { |
- if (desc.id) { idMap[desc.id] = desc; } |
+ var id = desc.getAttribute('id'); |
+ if (id) { idMap[id] = desc; } |
} |
} |
/** |
@@ -180,11 +181,16 @@ |
} |
// Reattach up to and including limit ancestor. |
var nConsumed = 0; |
- while (true) { |
- var toReattach = detached[nConsumed]; |
- (detached[nConsumed + 1] /* the parent */).appendChild(toReattach); |
+ while (nConsumed < detached.length) { |
MikeSamuel
2009/08/11 22:52:28
Why does this condition change?
felix8a
2009/08/12 08:05:17
last-ditch recovery in case we walk off the end of
MikeSamuel
2009/08/12 16:17:29
Fair enough. Please comment the condition so that
|
+ // in IE, some types of nodes can't be standalone, and detaching |
+ // one will create new parentNodes for them. so at this point, |
+ // limitAnc might be an ancestor of the node on detached. |
+ var reattach = detached[nConsumed]; |
+ var reattAnc = reattach; |
+ for (; reattAnc.parentNode; reattAnc = reattAnc.parentNode) {} |
+ (detached[nConsumed + 1] /* the parent */).appendChild(reattach); |
nConsumed += 2; |
- if (toReattach === limitAnc) { break; } |
+ if (reattAnc === limitAnc) { break; } |
} |
// Replace the reattached bits with the ones detached from limit. |
newDetached[1] = nConsumed; // splice's second arg is the number removed |