Page MenuHomePhabricator

jquery.byteLimit should allow the limit to be reached
Closed, ResolvedPublic

Description

See also https://bugzilla.wikimedia.org/show_bug.cgi?id=28650 and r86698 in which this module was created.

r91844 added a test suite exposed a bug.

jquery.byteLimit is preventing characters to be added as soon as byteLength(currentValue) + 3 is more than the given limit.

Consider the following scenarios:

byteLimit: 10
input: "123456890123456890" (20 chars, 20 bytes)
result: 8 chars
expected: 10 chars ("1234567890")

The last 2 characters were incorrectly prevented from insertion.

byteLimit: 14
input: "1234567890€1234567890€" (22 chars, 26 bytes; contains two euro-symbols of 3 bytes each)
result: 13 chars
expected: 14 ("1234567890" + "€" + 1)

The last one was incorrectly prevented.

byteLimit: 12
input: "1234567890€1234567890€"
result: 10 chars
expected: 10 ("1234567890". as the next 3-byte "€" would exceed the limit)

This third scenario is the only one correctly passing.


Version: unspecified
Severity: major

Details

Reference
bz29804

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:35 PM
bzimport set Reference to bz29804.

r91891 fixes these test cases:

  • take the char code and run it through jquery.byteLength instead of hardcoding 3 (keypress gets char codes, not keycodes)
  • fix for one test case that expected 10 chars but actually gets 12

Unknowns:

  • how does any of this interact with native OS input methods?
  • does any of this work with Narayam JS input method?
  • how does keypress handle non-BOM characters? Are they reported as two events with surrogate pairs? If so this may.... explode horribly with them. ;)
  • in general this keypress technique fails to handle paste and won't properly handle text selection replacement etc.

(In reply to comment #1)

  • in general this keypress technique fails to handle paste and won't properly

handle text selection replacement etc.

This is (also) coverered bug 29467.

switch to milestone, remove release tracking dep

how does keypress handle non-BOM characters? Are they reported as two events
with surrogate pairs? If so this may.... explode horribly with them. ;)

I think I tested this way back. I can't remember for sure but I think the answer was yes on some browsers.

Marking fixed for the cases that we opened the bug for.

For more advances cases, see bug 29467 instead.