maxlength attribute on text inputs don't handle surrogate pair characters properly
Reported by
edwardke...@gmail.com,
Jul 22 2017
|
|||
Issue descriptionUserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3155.0 Safari/537.36 Steps to reproduce the problem: 1. Create a textarea element with maxlength=1 2. Paste 👨 into the textarea What is the expected behavior? The character 👨 to be pasted in the textarea What went wrong? The character 👨 is not pasted in the textarea Did this work before? N/A Chrome version: 61.0.3155.0 Channel: stable OS Version: OS X 10.12.1 Flash Version: The character 👨 is a surrogate pair in UTF-16, however, JavaScript strings are counted by the number of the 16-bits of UTF-16, not the number of the code point, which makes the browser count the input as 2 character long string, and fails to paste it to the textarea. This behavior becomes a bit tricky when you want to control string inputs that may contain special Chinese characters in Japanese such as 𠮷 as well as most of the emojis. This is acceptable when you have access to APIs that can handle the string by its code points like using spread operator to the string or the unicode flag of the regex match function. Yet, for DOM attributes like maxlength or minlength, users do not have any control over this behavior and it does not reflect how characters should be counted by its code point.
,
Jul 24 2017
,
Jul 24 2017
This works as expected according to the current specification. We know the current behavior doesn't work well in many cases. There is a specification issue: https://github.com/whatwg/html/issues/1467
,
Jul 29 2017
Thanks a lot for the link, will follow the discussion there. |
|||
►
Sign in to add a comment |
|||
Comment 1 by edwardke...@gmail.com
, Jul 24 2017