Bug 1636855 - Disallow to paste longer text than maxlength value except in Nightly channel and early Beta r=emilio

Fix of bug 1320229 allowed to paste longer text than `maxlength` attribute of
`<input>` and `<textarea>` because it was thought that the longer text causes
"too long" invalidate state, makes users notified and prevent to submit
form data.

However, according to Bug 1636855 comment 7 (*1), it breaks a major enterprise
web app, SAP, at least because it sends form data without checking validity of
each form data and discards invalid data on server side silently.

According to bug 1636855 comment 24 (*2), one of new behavior's fault is
on Gecko side too.  The style of `<input>` element or `<textarea>` element
which has too long text after pasting is changed when it loses focus.
Therefore, users can post the data before they know pasted data is too
long if sending the form data with `Enter` key or something immediately
after pasting (i.e., without moving focus) web apps handle it by themselves.

On the other hand, the original bug report, bug 1320229, should be solved in
the future especially in password field because users may register password
which is cut by `maxlength` silently and they don't use builtin password
manager, only the pasted password is saved, and then, they won't be able to
login as the account.  This is really long standing issue of the web forms.
An article (*3) warned this to web developers in 2011.  Therefore, we should
keep going advance for solving this issue at least in Nightly channel to get
more feedback from testers and web developers.

1 https://bugzilla.mozilla.org/show_bug.cgi?id=1636855#c7
2 https://bugzilla.mozilla.org/show_bug.cgi?id=1636855#c24
3 https://www.christophermanning.org/writing/dont-use-maxlength-on-password-inputs

Differential Revision: https://phabricator.services.mozilla.com/D78613
This commit is contained in:
Masayuki Nakano 2020-06-07 21:29:48 +00:00
parent 2897696021
commit 72a41b4a70
4 changed files with 13 additions and 5 deletions

View File

@ -32,8 +32,13 @@ SimpleTest.waitForFocus(function() {
function() {
i.focus();
synthesizeKey("V", {accelKey: true});
is(i.value, src.textContent,
"Pasting should paste the clipboard contents regardless of maxlength");
if (!SpecialPowers.getBoolPref("editor.truncate_user_pastes")) {
is(i.value, src.textContent,
"Pasting should paste the clipboard contents regardless of maxlength");
} else {
is(i.value, src.textContent.substr(0, i.maxLength),
"Pasting should paste maxlength chars worth of the clipboard contents");
}
SimpleTest.finish();
},
function() {

View File

@ -24,7 +24,8 @@ is then marked as `tooLong`.
/** Test for Bug 1320229 **/
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
SimpleTest.waitForFocus(async function() {
await SpecialPowers.pushPrefEnv({"set": [["editor.truncate_user_pastes", false]]});
var src = document.getElementById("src");
var pwd = document.getElementById("form-password");
SimpleTest.waitForClipboard(src.textContent,

View File

@ -30,7 +30,9 @@ Inspired by `dom/html/test/forms/test_MozEditableElement_setUserInput.html`.
// eslint-disable-next-line complexity
SimpleTest.waitForFocus(async () => {
await SpecialPowers.pushPrefEnv({
set: [["dom.input_events.beforeinput.enabled", true]],
set: [["dom.input_events.beforeinput.enabled", true],
["editor.truncate_user_pastes", false],
],
});
let content = document.getElementById("content");

View File

@ -3305,7 +3305,7 @@
# Whether user pastes should be truncated.
- name: editor.truncate_user_pastes
type: bool
value: false
value: @IS_NOT_EARLY_BETA_OR_EARLIER@
mirror: always
# How line breakers are treated in single line editor: