Closed Bug 1849790 Opened 3 years ago Closed 1 month ago

Stop setting ill-formed UTF-16 to `KeyboardEvent.key` and `InputEvent.data` when typing a surrogate pair in release builds

Categories

(Core :: DOM: Events, defect)

defect

Tracking

()

RESOLVED FIXED
154 Branch
Tracking Status
firefox154 --- fixed

People

(Reporter: masayuki, Assigned: masayuki)

References

Details

Attachments

(1 file)

Bug 1840519 introduces prefs to control how we expose a typing of a surrogate pair.

dom.event.keypress.dispatch_once_per_surrogate_pair is default to false in all channels because even though Chrome and Safari dispatches only one keypress event for a surrogate pair input on macOS (and probably on Linux and Android too for Chrome), this breaks existing web apps which use String.fromCharCode(event.charCode).

I think that we do not need to change this because of the backward compatibility.

dom.event.keypress.key.allow_lone_surrogate is default to false on early beta builds and earlier. Once we set this to false, first keypress will have a surrogate pair to .key and high-surrogate to .charCode, and second keypress will have empty string to .key and low-surrogate to .charCode. Then, TextEditor and HTMLEditor do not handle surrogates separately. Therefore, InputEvent.data will have a surrogate pair.

I think that this behavior is reasonable for both modern web apps and legacy web apps using String.fromCharCode. However, this is not compatible with the other browsers on any platforms.

The pref was added in bug 1840519, 3 years ago. The motivation of the
new behavior is, String.fromCharCode(event.charCode) won't create
ill-formed UTF-16 string only from the high-surrogate or the
low-surrogate.

Unfortunately, this behavior is incompatible with Chrome, but we don't
get any bug reports from our testers in this 3 years. So, I think
shipping this is enough safe and the new behavior is better from the
Unicode spec point of view.

Note that there must be only a few keyboard layouts which can type
non-BMP characters directly. I tried to test it with creating a
custom keyboard layout (attachment 9341661 [details]). So, originally, this bug
affected only a small number of users.

Assignee: nobody → masayuki
Status: NEW → ASSIGNED

Comment on attachment 9604608 [details]
Bug 1849790 - Ship the better keypress.charCode behavior when typing a surrogate pair r=smaug!

Revision D310450 was moved to bug 2052478. Setting attachment 9604608 [details] to obsolete.

Attachment #9604608 - Attachment is obsolete: true
Attachment #9604608 - Attachment is obsolete: false
Status: ASSIGNED → RESOLVED
Closed: 1 month ago
Resolution: --- → FIXED
Target Milestone: --- → 154 Branch
QA Whiteboard: [qa-triage-done-c155/b154]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: