Skip to content

Commit 982c126

Browse files
committed
Fix unicode length comparisons
the test suite had the wrong expected values for max/minLength for unicode strings, they've been updated. Use the number of unicode codepoints to compare lengths.
1 parent 6a8bf59 commit 982c126

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

core/src/main/java/org/everit/json/schema/StringSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public Pattern getPattern() {
131131
}
132132

133133
private List<ValidationException> testLength(final String subject) {
134-
int actualLength = subject.length();
134+
int actualLength = subject.codePointCount(0, subject.length());
135135
List<ValidationException> rval = new ArrayList<>();
136136
if (minLength != null && actualLength < minLength.intValue()) {
137137
rval.add(new ValidationException(this, "expected minLength: " + minLength + ", actual: "

tests/src/test/resources/org/everit/json/schema/draft4/maxLength.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
{
2929
"description": "two supplementary Unicode code points is long enough",
3030
"data": "\uD83D\uDCA9\uD83D\uDCA9",
31-
"valid": false
31+
"valid": true
3232
}
3333
]
3434
}

tests/src/test/resources/org/everit/json/schema/draft4/minLength.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
{
2929
"description": "one supplementary Unicode code point is not long enough",
3030
"data": "\uD83D\uDCA9",
31-
"valid": true
31+
"valid": false
3232
}
3333
]
3434
}

0 commit comments

Comments
 (0)