GWicke has submitted this change and it was merged.
Change subject: LinkHandler: Clone tokens before modifying them.
......................................................................
LinkHandler: Clone tokens before modifying them.
* One more instance where cloning was required.
* Add missing check for non-empty stack.
* 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, 21 insertions(+), 10 deletions(-)
Approvals:
GWicke: Verified; Looks good to me, approved
diff --git a/js/lib/ext.core.LinkHandler.js b/js/lib/ext.core.LinkHandler.js
index e57680b..72bac31 100644
--- a/js/lib/ext.core.LinkHandler.js
+++ b/js/lib/ext.core.LinkHandler.js
@@ -507,25 +507,36 @@
// 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,
+ // Store the index of a token in the 'tokens' array
+ // rather than the token itself.
+ openBlockTagStack = [];
+
+ for (i = 0, n = tokens.length; i < n; i++) {
t = tokens[i];
if (Util.isBlockToken(t)) {
if (t.constructor === TagTk) {
- openBlockTagStack.push(t);
- } else if (t.constructor === EndTagTk) {
- if (openBlockTagStack.last().name ===
t.name) {
+ openBlockTagStack.push(i);
+ } else if (t.constructor === EndTagTk &&
openBlockTagStack.length > 0) {
+ if
(tokens[openBlockTagStack.last()].name === t.name) {
openBlockTagStack.pop();
}
}
}
}
- for (i = 0, n = openBlockTagStack.length; i < n; i++) {
- t = openBlockTagStack.pop();
- t.dataAttribs.autoInsertedEnd = true;
- tokens.push(new EndTagTk(t.name));
+ n = openBlockTagStack.length;
+ if (n > 0) {
+ if (Object.isFrozen(tokens)) {
+ tokens = tokens.slice();
+ }
+ for (i = 0; i < n; i++) {
+ j = openBlockTagStack.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: merged
Gerrit-Change-Id: I8f0e422ec4bbc04db6654c2accc92a49fa0b8c8a
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits