Open Bug 1542530 Opened 7 months ago Updated 5 months ago

Selection.toString() return an empty string

Categories

(Core :: Serializers, defect, P3, minor)

66 Branch
defect

Tracking

()

Tracking Status
firefox-esr60 --- wontfix
firefox66 --- wontfix
firefox67 --- fix-optional
firefox68 --- wontfix

People

(Reporter: mad1ost, Assigned: baku, NeedInfo)

References

(Regression)

Details

(4 keywords)

Attachments

(4 files)

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 YaBrowser/19.3.1.777 (beta) Yowser/2.5 Safari/537.36

Steps to reproduce:

I select some text with mouse on stackoverflow.com (I showed the mouse movement on the attachment).

Actual results:

Selection.toString() return an empty string

Expected results:

as well as Range.toString() return a text

I can reproduce the issue on Nightly68.0a1 windows10.

STR

  1. Open https://stackoverflow.com/questions/10510191/valid-to-use-a-anchor-tag-without-href-attribute?answertab=active#tab-top
  2. Drag selection from left side blank area of "T" and to the right
  3. Evaluate window.getSelection().toString() in Web Console

Actual Results:

  • window.getSelection().toString();, then it returns "".
  • window.getSelection().getRangeAt(0).toString();, then it seems to work as expected.

And

  • If Drag select from on the character of "T" and to the right, then it works as expected.
Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core

And there are more problems.

  • Right click context menu 'Search Google for xxxx...' is missing.
  • Right click context menu 'View Selection Source' fails to highlight selected text in source viewer
  • And Ctrl + F does not fetch the selected text.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Component: DOM: Core & HTML → Selection
Severity: normal → minor
Keywords: testcase-wanted
Priority: -- → P3
Attached file testcase html

Drag selection from 1st line(svg image line) to 2nd line text

Has STR: --- → yes

Regression window:
https://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=fc1f453bb9538d292fd325f3ecea742aaa5edd60&tochange=a3887394965f161d011eebc74e8987a653366e4b

Suspect:
0b1c98a4a3d4 Andrea Marchesini — Bug 1425440 - Introduce nsINode::RemoveChildNode, r=catalinb
f1035d52904d Andrea Marchesini — Bug 1425440 - Get rid of GetChildAt_Deprecated in nsDocumentEncoder, r=catalinb

:baku
Your bunch of patch seems to cause the regression, Can you please look into this?

Flags: needinfo?(amarchesini)
Keywords: regression
Regressed by: 1425440
Has Regression Range: --- → yes

Looks like a regression from this chunk:
https://searchfox.org/mozilla-central/diff/205d40e2d7c06a4a260857777bd4054c1a9ce1e4/dom/base/nsDocumentEncoder.cpp#736
We used to do for (j=startOffset; j<endOffset; j++) which would
skip this block if startOffset >= endOffset, but now we enter
the block and iterate until we find the child at startOffset.
It just so happens that startOffset is after the last child
in this case (I think that's a valid offset, but I don't know).
(So we return with a failure in
NS_ENSURE_TRUE(!!childAsNode, NS_ERROR_FAILURE).)

Component: Selection → Serializers

This fixes it BTW:

-      if (endOffset) {
+      if (startOffset < endOffset) {

mats, do you mind to submit a patch? I can review it.

Flags: needinfo?(amarchesini) → needinfo?(mats)

Sorry, busy, no time to write up testcase and all that...

Flags: needinfo?(mats)

:baku, can you take a look at this one?

Flags: needinfo?(amarchesini)
Assignee: nobody → amarchesini
Flags: needinfo?(amarchesini)
Pushed by amarchesini@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/78ed7f9d6566
Selection.toString() works correctly when text is selected together with a set of div+svg elements, r=mats

Bulk change to wontfix for 68 (P3+ carryover with needinfo).

You need to log in before you can comment on or make changes to this bug.