Closed Bug 594606 Opened 14 years ago Closed 12 years ago

Selection.toString behaviour does not conform to HTML5 draft

Categories

(Core :: DOM: Selection, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: timdown, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9
Build Identifier: 

According to the selection section of the HTML5 draft

"Objects implementing this interface must stringify to a concatenation of the results of invoking the toString()  method of the Range object on each of the ranges of the selection, in the order they appear in the list (first to last)." 

This is not what happens in Mozilla (or WebKit, but is what happens in Opera), where Selection.toString() returns only the visible text within the selection (which seems like the correct behaviour to me). Consider the following piece of HTML (selection delimited by pipes):

<div>|One<script>var x = 1;</script>two|</div>

Calling toString() on a Range representing that selection would produce "Onevarx = 1;two", while calling toString() on the Selection object will produce "Onetwo". The latter behaviour is contrary to HTML5's specified behaviour, according to which it should return the same string as the Range.

I think Mozilla and WebKit have the correct behaviour here and would rather the HTML5 spec was altered.

Reproducible: Always
If you want the spec to change, you're filing this in the wrong bugzilla. :)

You probably want http://www.w3.org/Bugs/Public/enter_bug.cgi?product=HTML%20WG&component=HTML5%20spec%20%28editor:%20Ian%20Hickson%29
I already have: http://www.w3.org/Bugs/Public/show_bug.cgi?id=10583. I posted the Mozilla bug to bring it to your attention, in case the HTML5 spec doesn't change.
The spec subsequently changed to not define Selection.toString() at all.  The current definition is a todo:

http://dvcs.w3.org/hg/editing/raw-file/9b1189899718/editing.html#dom-selection-stringifier

So this is invalid for now.
Status: UNCONFIRMED → RESOLVED
Closed: 12 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.