Bug 1341137 part 1 - Make Selection::addRange silently reject ranges that have a different root. r=smaug
authorMats Palmgren <mats@mozilla.com>
Sat, 25 Feb 2017 11:33:34 +0100
changeset 344931 e9764fc002e8791215e13accf181ad5902c85d09
parent 344928 5144d2aa92af110e8fdf3ea377524a201990f882
child 344932 31f4db063fe85475ac31401318a6dfa80bccd28f
push id37977
push userphilringnalda@gmail.com
push dateSat, 25 Feb 2017 21:34:46 +0000
treeherderautoland@10bfa931c92f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1341137
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1341137 part 1 - Make Selection::addRange silently reject ranges that have a different root. r=smaug
layout/generic/nsSelection.cpp
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -4959,16 +4959,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;