Page MenuHomePhabricator

OO.ui.TextInputWidget's maxLength option limits by UTF-16 code units, not characters as documented
Closed, ResolvedPublic


The maxLength configuration option to OO.ui.TextInputWidget is documented as "Maximum number of characters allowed in the input." However, what it actually does is set the maxLength attribute on the HTML <input> element, which according to HTML5 specifies the maximum length in "code units".

This makes a difference if someone is entering characters from outside the Unicode Basic Multilingual Plane, as in UTF-16 these characters consist of two code units.

I'll leave it to you to decide whether the better fix is to stop using the HTML5 maxLength attribute in favor of manual validation or to simply update the documentation to reference code units rather than characters.

Event Timeline

Anomie created this task.Nov 14 2017, 4:58 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptNov 14 2017, 4:58 PM

Note this is becoming more relevant with T185948: Update web UI for increased comment length, which will want to be limiting values to 1000 Unicode characters.

matmarex claimed this task.Feb 5 2018, 5:23 PM
matmarex added a subscriber: matmarex.

I'm going to update the docs.

Change 408312 had a related patch set uploaded (by Bartosz Dziewoński; owner: Bartosz Dziewoński):
[oojs/ui@master] TextInputWidget: Document that 'maxLength' counts UTF-16 code units

Change 408312 merged by jenkins-bot:
[oojs/ui@master] TextInputWidget: Document that 'maxLength' counts UTF-16 code units

matmarex closed this task as Resolved.Feb 5 2018, 8:50 PM
matmarex removed a project: Patch-For-Review.
Volker_E moved this task from Backlog to OOUI-0.25.2 on the OOUI board.Feb 5 2018, 9:40 PM
Volker_E edited projects, added OOUI (OOUI-0.25.2); removed OOUI.
matmarex updated the task description. (Show Details)Feb 8 2018, 8:51 PM
Aklapper removed a subscriber: Anomie.Fri, Oct 16, 5:39 PM