Bug 1341137 part 1 - Make Selection::addRange silently reject ranges that have a different root. r=smaug a=jcristau
authorMats Palmgren <mats@mozilla.com>
Sat, 25 Feb 2017 11:33:34 +0100
changeset 376454 20d59272b035c6b81568e95e0efbf4aa8fd01843
parent 376453 cbd562b2b0b34dcdad2da531645c345e87123b33
child 376455 c3f3a0fa748e798ee57da04ea7441b1051f0d651
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, jcristau
bugs1341137
milestone53.0a2
Bug 1341137 part 1 - Make Selection::addRange silently reject ranges that have a different root. r=smaug a=jcristau
layout/generic/nsSelection.cpp
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -4952,16 +4952,26 @@ Selection::AddRange(nsIDOMRange* aDOMRan
   ErrorResult result;
   AddRange(*range, result);
   return result.StealNSResult();
 }
 
 void
 Selection::AddRange(nsRange& aRange, ErrorResult& aRv)
 {
+  nsINode* rangeRoot = aRange.GetRoot();
+  nsIDocument* doc = GetParentObject();
+  if (doc != rangeRoot && (!rangeRoot ||
+                           doc != rangeRoot->GetComposedDoc())) {
+    // http://w3c.github.io/selection-api/#dom-selection-addrange
+    // "...  if the root of the range's boundary points are the document
+    // associated with context object. Otherwise, this method must do nothing."
+    return;
+  }
+
   // This inserts a table cell range in proper document order
   // and returns NS_OK if range doesn't contain just one table cell
   bool didAddRange;
   int32_t rangeIndex;
   nsresult result = addTableCellRange(&aRange, &didAddRange, &rangeIndex);
   if (NS_FAILED(result)) {
     aRv.Throw(result);
     return;