-
Bug
-
Resolution: Done
-
Medium
-
None
-
None
Currently this YANG:
typedef foo { type string { length 1; } }
translates to this enforcement code:
private static void check_valueLength(final String value) { final int length = value.length(); if (length == 1) { return; } CodeHelpers.throwInvalidLength("[[1..1]]", value); }
which looks good on surface, but has a slight flaw. RFC7950 specifies that:
A "length" statement restricts the number of Unicode characters in the string.
What we are checking is the number of code units, not code points. The difference becomes obvious when characters outside the Basic Multilingual Plane are encountered:
// U+1F31E final String str = "�" // Encodes as "\u0xD83C\u0xDF1E", i.e. two code units assertEquals(2, str.length()); // The two code units together yield a single code point assertEquals(1, str.codePointCount(0, str.length());
- relates to
-
YANGTOOLS-1224 Data codecs may mis-enforce String length constraints
- Resolved