Subramanya Sastry has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/51335


Change subject: LinkHandler: Clone tokens before modifying them.
......................................................................

LinkHandler: Clone tokens before modifying them.

* One more instance where cloning was required.
* No change in parser test results.
* Fixes crashers in several pages found in RT testing.

Change-Id: I8f0e422ec4bbc04db6654c2accc92a49fa0b8c8a
---
M js/lib/ext.core.LinkHandler.js
1 file changed, 19 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid 
refs/changes/35/51335/1

diff --git a/js/lib/ext.core.LinkHandler.js b/js/lib/ext.core.LinkHandler.js
index e57680b..110aa22 100644
--- a/js/lib/ext.core.LinkHandler.js
+++ b/js/lib/ext.core.LinkHandler.js
@@ -507,25 +507,34 @@
        // too. This would need to apply phase 3 token transforms, as the 
caption
        // as an attribute is already expanded to phase 2.
        function closeUnclosedBlockTags(tokens) {
-               var t;
-               var openBlockTagStack = [];
-               for (var i = 0, n = tokens.length; i < n; i++) {
+               var i, j, n, t,
+                       openBlockTagIdxStack = [];
+
+               for (i = 0, n = tokens.length; i < n; i++) {
                        t = tokens[i];
                        if (Util.isBlockToken(t)) {
                                if (t.constructor === TagTk) {
-                                       openBlockTagStack.push(t);
+                                       openBlockTagIdxStack.push(i);
                                } else if (t.constructor === EndTagTk) {
-                                       if (openBlockTagStack.last().name === 
t.name) {
-                                               openBlockTagStack.pop();
+                                       if 
(tokens[openBlockTagIdxStack.last()].name === t.name) {
+                                               openBlockTagIdxStack.pop();
                                        }
                                }
                        }
                }
 
-               for (i = 0, n = openBlockTagStack.length; i < n; i++) {
-                       t = openBlockTagStack.pop();
-                       t.dataAttribs.autoInsertedEnd = true;
-                       tokens.push(new EndTagTk(t.name));
+               n = openBlockTagIdxStack.length;
+               if (n > 0) {
+                       if (Object.isFrozen(tokens)) {
+                               tokens = tokens.slice();
+                       }
+                       for (i = 0; i < n; i++) {
+                               j = openBlockTagIdxStack.pop();
+                               t = tokens[j].clone();
+                               t.dataAttribs.autoInsertedEnd = true;
+                               tokens[j] = t;
+                               tokens.push(new EndTagTk(t.name));
+                       }
                }
 
                return tokens;

-- 
To view, visit https://gerrit.wikimedia.org/r/51335
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8f0e422ec4bbc04db6654c2accc92a49fa0b8c8a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to