Live data from Hacker News

Text exceeding maxlength will no longer be truncated when pasted in Firefox 77

fxsitecompat.dev

71–80 of 145 posts

Re: Text exceeding maxlength will no longer be truncated when pasted in Firefox 77

#71
post #3

This breaks my use case function shorten(text, length) const t = document.createElement('input') t.maxlength = length t.value = text return t.value }

Something similar was used to parse URLs: https://stackoverflow.com/questions/6168260/how-to-parse-a-u...

Re: Text exceeding maxlength will no longer be truncated when pasted in Firefox 77

#73
post #63

Earlier quoted context omitted.

Even if you use AJAX forms for logging in or registering (I'd prefer you didn't but whatever), you should still use the proper form validation API for things like this. If you use the proper HTML API for gathering data properly, you're most likely not affected badly functionality wise; only your UI will be affected because the form will refuse to be posted without proper explanation. If the change really does get byp…

>Even if you use AJAX forms for logging in or registering (I'd prefer you didn't but whatever), you should still use the proper form validation API for things like this. You don't even need to use "the proper form validation API". It's as simple as changing your ajax call from an onclick (on the submit button) to an onsubmit (on the form).

Agreed. Though, as a developer, I like to extend the submission actions a little bit to make error messages fit in with the rest of the site and maybe suggest what to do in order to correct the input (e.g. remove letters from phone numbers, pick a better password, etc.)

I do consider using the HTML5 form validation to be the proper validation API. Browser can do a lot without javascript and relying on their default behaviour is still making use of the validation API.

Re: Text exceeding maxlength will no longer be truncated when pasted in Firefox 77

#74

They should remove maxlength altogether; it breaks the expected behavior of textboses wherein pressing a key when focus is in a textbox inserts the character corresponding to that key.

Should they also remove type="number"? It breaks that expectation too.

Re: Text exceeding maxlength will no longer be truncated when pasted in Firefox 77

#75

Earlier quoted context omitted.

...I think it's reasonable for there to be some limit, right? Lest a user submit a 50,000 character password?

Nope. Not reasonable, and likely of no benefit to anyone. That'd be like 50kb... assuming it doesn't cause your hashing algorithm to take a shit causing breakage. 50kb to on one request, sitting pretty much at rest 99.9% of the time, is nothing to even bother with. Most folks should probably spend more time worry about optimizing their own payloads instead of their users [1]. [1] To that point, most people want to sp…

What about 500kB? 5mB? At what point does it become reasonable to spend a few extra minutes on sanitizing user input?

Re: Text exceeding maxlength will no longer be truncated when pasted in Firefox 77

#76
post #71
post #3

This breaks my use case function shorten(text, length) const t = document.createElement('input') t.maxlength = length t.value = text return t.value }

Something similar was used to parse URLs: https://stackoverflow.com/questions/6168260/how-to-parse-a-u...

You can just use the URL object now

https://developer.mozilla.org/en-US/docs/Web/API/URL

Re: Text exceeding maxlength will no longer be truncated when pasted in Firefox 77

#77

Highlights from the bug report[1][2]: - HTML spec allows it; says MAY, not MUST [3] - Affects only user pastes, not javascript edits - Affects all input boxes, not just password ones - New preference editor.truncate_user_pastes can restore old behavior As a developer, I personally find the inconsistent behavior of maxLength unintuitive and am surprised a potentially-breaking change like this didn't have more discussi…

We discussed the problem on #security and we moved to bugzilla once we kinda had a solution (it is hard to discuss solutions on bugzilla. :) Here is a link to the chat: https://matrix.to/#/!xSFwJMLGSLXLaSUrHr:mozilla.org/$o3a38gf...

Re: Text exceeding maxlength will no longer be truncated when pasted in Firefox 77

#78

This is a welcome change, but what would make it even more awesome is a little red bar at the last character that fits into the maxlength. A semi-common thing I do is paste a long thing of text into an exerpt text area, let it truncate to maxlength and manually tweak the ending. A little red bar to tell me where it would've gotten truncated would make that still possible, while fixing the dangerous behavior with trun…

Yup, that would be awesome, maybe file an enhancement on bugzilla.

Re: Text exceeding maxlength will no longer be truncated when pasted in Firefox 77

#79
post #8
post #3

This breaks my use case function shorten(text, length) const t = document.createElement('input') t.maxlength = length t.value = text return t.value }

I know you're joking, but this reminded me of https://xkcd.com/1172/

Me too. I suspect this was intentional :)

Re: Text exceeding maxlength will no longer be truncated when pasted in Firefox 77

#80

From the WHATWG/W3C definitions of the maxlength attribute: > Constraint validation: If an element has a maximum allowed value length, its dirty value flag is true, its value was last changed by a user edit (as opposed to a change made by a script), and the code-unit length of the element’s value is greater than the element’s maximum allowed value length, then the element is suffering from being too long. > User agen…

Arguably truncating the text is against the specification as it only specifies that the user agent may prevent the user from going beyond the max-length, not that it may do arbitrary stuff to make the text fit.

I also hope it will make at least some developers realise that client-side validation is a bad idea.

Post reply on HN