GWicke has submitted this change and it was merged.

Change subject: Handle flipped tpl-ranges in findTopLevelNonOverlappingRanges
......................................................................


Handle flipped tpl-ranges in findTopLevelNonOverlappingRanges

* Because of fostered of end-tags, a range's end and start tags
  might be flipped.  In such a scenario, two ranges A and B
  might have exactly identical ranges.

     A = {start: e1, end: e2}
     B = {start: e2, end: e1} where B is the flipped range.

  With these two ranges, it doesn't matter how we handle nesting.
  It is okay to consider A nested in B or the other other way
  round as long as we dont introduce a nesting loop.

  The logic in findTopLevelNonOverlappingRanges was missing a
  check to handle this scenario. When testing if B is nested
  in A, it wasn't checking if A was already nested in B.  Without
  this check, we will record that A is nested in B and B is nested
  in A which will introduce a loop in findToplevelEnclosingRange!

* Here is a reduced example extracted from Dogma_studio:

    <table>
    {{echo|<div>}}
    foo
    {{echo|</div>}}
    </table>

  Before this patch, this snippet sent the code into an infinite
  loop.  With this patch, the code terminates.  There is an
  unrelated error that this snippet exposes -- the fostering of
  the entire content in the table tags doesn't get encapsulated
  properly becausing of missing DSR information.  So, this snippet
  doesn't RT yet.  That will be addressed in a different commit.

  As expected, this content is fostered out in the PHP parser as
  well, but the PHP parser doesn't have to deal with RTing these
  buggy wikitext snippets exactly as they were.

* No change in parser test results.

* en:Dogma studio parses and isn't stuck in an infinite loop.

Change-Id: I32f643dbc6ae156726c490fbcf04fd86f44df82e
---
M js/lib/mediawiki.DOMPostProcessor.js
1 file changed, 16 insertions(+), 2 deletions(-)

Approvals:
  GWicke: Verified; Looks good to me, approved
  jenkins-bot: Checked



diff --git a/js/lib/mediawiki.DOMPostProcessor.js 
b/js/lib/mediawiki.DOMPostProcessor.js
index ee68bd9..215e182 100644
--- a/js/lib/mediawiki.DOMPostProcessor.js
+++ b/js/lib/mediawiki.DOMPostProcessor.js
@@ -996,10 +996,24 @@
                                                foundIntersection = false;
 
                                        for (var j = 0; j < s_keys.length; j++) 
{
-                                               if (s_keys[j] !== r.id && 
e_tpls[s_keys[j]]) {
+
+                                               // Because of fostered of 
end-tags, a range's end and start
+                                               // tags might be flipped 
(r.flipped).  In such a scenario,
+                                               // two ranges A and B might 
have exactly identical ranges.
+                                               //
+                                               //   A = {start: e1, end: e2}
+                                               //   B = {start: e2, end: e1} 
where B is the flipped range.
+                                               //
+                                               // Hence we also need an 
additional check to make sure
+                                               // nestedRangesMap[other] !== 
r.id.  Without this check,
+                                               // we will record that A is 
nested in B and B is nested in A
+                                               // which will introduce a loop 
in findToplevelEnclosingRange!
+
+                                               var other = s_keys[j];
+                                               if (other !== r.id && 
e_tpls[other] && nestedRangesMap[other] !== r.id) {
                                                        foundIntersection = 
true;
                                                        // Record a range in 
which 'r' is nested in.
-                                                       nestedRangesMap[r.id] = 
s_keys[j];
+                                                       nestedRangesMap[r.id] = 
other;
                                                        break;
                                                }
                                        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I32f643dbc6ae156726c490fbcf04fd86f44df82e
Gerrit-PatchSet: 1
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

Reply via email to