Closed Bug 1057841 Opened 5 years ago Closed 5 years ago

highlighting of the selection in viewPartialSource breaks if document contains a sequence of ZWSP characters

Categories

(Toolkit :: View Source, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla34

People

(Reporter: jfkthame, Assigned: jfkthame)

References

(Depends on 1 open bug)

Details

Attachments

(1 file)

Testcase:

data:text/html,hello&%23x200b;&%23x200b;&%23x200b;&%23x200b;&%23x200b; cruel world!

Double-click on the word "world" to highlight it.

Right-click and choose View Selection Source.

Expected:
The word "world" should be highlighted in the source view.

Actual:
The text " cruel " is highlighted.

The problem occurs because of the use of a delimiter string at https://mxr.mozilla.org/mozilla-central/source/toolkit/components/viewsource/content/viewPartialSource.js#25 that can legitimately occur as part of the document text; if that happens, we lose track of the intended selection range.

I suggest using noncharacter codepoints as the delimiters to minimize the risk of this.
Assignee: nobody → jfkthame
Status: NEW → ASSIGNED
Attachment #8477990 - Flags: review?(gavin.sharp)
Comment on attachment 8477990 [details] [diff] [review]
use noncharacters as selection delimiters in viewPartialSource.js.

>diff --git a/toolkit/components/viewsource/content/viewPartialSource.js b/toolkit/components/viewsource/content/viewPartialSource.js

>-// safety (and futhermore, these are known to be mapped to a 0-length string
>-// in transliterate.properties)

Why was this considered important for the previous characters? The new ones don't share this property, is that a problem?

I don't know anything about how this code works, and it's very old. The code seems to go back to bug 122524. bz reviewed it 12 years ago, maybe he'd enjoy a blast from the past? :)
Comment on attachment 8477990 [details] [diff] [review]
use noncharacters as selection delimiters in viewPartialSource.js.

bz, see comment 2
Attachment #8477990 - Flags: feedback?
Attachment #8477990 - Flags: feedback? → feedback?(bzbarsky)
Comment on attachment 8477990 [details] [diff] [review]
use noncharacters as selection delimiters in viewPartialSource.js.

I think the goal was to use chars that wouldn't show up even if we somehow failed to replace them or some such.

This looks fine to me.
Attachment #8477990 - Flags: feedback?(bzbarsky) → feedback+
Attachment #8477990 - Flags: review?(gavin.sharp) → review+
https://hg.mozilla.org/mozilla-central/rev/f307e36bade8
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
QA Whiteboard: [good first verify]
Depends on: 1268344
You need to log in before you can comment on or make changes to this bug.