Arlolra has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/405821 )
Change subject: Fix infinite recursion from linting named ref cycles ...................................................................... Fix infinite recursion from linting named ref cycles On pages like, http://localhost:8000/fr.wikipedia.org/v3/page/html/Krzysztof_Charamsa/142052535 http://localhost:8000/es.wikipedia.org/v3/page/html/Taxonom%C3%ADa/104913080 Bug: T185267 Change-Id: I156cce384873609a65b659360667323b8f0a497b --- M lib/ext/Cite/index.js M lib/utils/DOMUtils.js M tests/mocha/linter.js 3 files changed, 25 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid refs/changes/21/405821/1 diff --git a/lib/ext/Cite/index.js b/lib/ext/Cite/index.js index d2b27e4..25319e2 100644 --- a/lib/ext/Cite/index.js +++ b/lib/ext/Cite/index.js @@ -182,6 +182,10 @@ }; Ref.prototype.lintHandler = function(ref, env, tplInfo, domLinter) { + // Don't lint the content of ref in ref, since it can lead to cycles + // using named refs + if (DU.fromExtensionContent(ref, 'references')) { return ref.nextNode; } + var linkBackId = ref.firstChild.getAttribute('href').replace(/[^#]*#/, ''); var refNode = ref.ownerDocument.getElementById(linkBackId); if (refNode) { diff --git a/lib/utils/DOMUtils.js b/lib/utils/DOMUtils.js index abb1eb2..3b90142 100644 --- a/lib/utils/DOMUtils.js +++ b/lib/utils/DOMUtils.js @@ -2891,6 +2891,21 @@ } }; +/** + * Is the node from extension content? + */ +DOMUtils.fromExtensionContent = function(node, extType) { + var parentNode = node.parentNode; + var extReg = new RegExp('\\bmw:Extension\\/' + extType + '\\b'); + while (parentNode && !DU.atTheTop(parentNode)) { + if (extReg.test(parentNode.getAttribute('typeof'))) { + return true; + } + parentNode = parentNode.parentNode; + } + return false; +}; + if (typeof module === "object") { module.exports.DOMUtils = DOMUtils; } diff --git a/tests/mocha/linter.js b/tests/mocha/linter.js index 5b3b82f..4195f2a 100644 --- a/tests/mocha/linter.js +++ b/tests/mocha/linter.js @@ -945,5 +945,11 @@ result[1].templateInfo.should.have.a.property("name", "Template:1x"); }); }); + it('should not get into a cycle trying to lint ref in ref', function() { + return parseWT("{{#tag:ref|<ref name='y' />|name='x'}}{{#tag:ref|<ref name='x' />|name='y'}}<ref name='x' />") + .then(function() { + return parseWT("{{#tag:ref|<ref name='x' />|name=x}}"); + }); + }); }); }); -- To view, visit https://gerrit.wikimedia.org/r/405821 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I156cce384873609a65b659360667323b8f0a497b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Arlolra <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
