Skip to content

Length bounds count characters, never bytes

A limit measured in bytes would depend on the alphabet the author writes in, so the same word would fit one implementation and not another.

The rule

Normative: this is the rule
  1. A string config value shorter than its schema's minLength or longer than its maxLength MUST be refused with R6_CONFIG_INVALID at node.{id}.config.{key}.
  2. Both bounds MUST count Unicode code points, never bytes.

What it means

A length bound is measured against how many code points a string is written in, not how many bytes it takes up. A value that is well within a bound when counted one way can be over it when counted the other, and the two counts diverge exactly for the text a byte-based check would punish hardest: text written outside the single-byte range.

Example

A key's schema requires at least five code points; the value assigned to it is four characters long, eight bytes in a multi-byte encoding:

A schema requiring at least five code points
{"type": "string", "minLength": 5}
The value assigned to that keyrefused
"äöüß"

Four code points is short of the minimum of five, even though the same value is eight bytes long.

Why

Recorded under OPEN-25.

Rule identifiers are permanent and are never renumbered. Each implementation publishes its own standing against these rules; this specification does not.spec 1.0 · R6.g · changed in spec 1.0