Skip to content

Commit b101658

Browse files
committed
fixes #4 unicode length
1 parent f653dad commit b101658

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

src/main/java/com/networknt/schema/MaxLengthValidator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
4848
// ignore no-string typs
4949
return errors;
5050
}
51-
52-
if (node.textValue().length() > maxLength) {
51+
if (node.textValue().codePointCount(0, node.textValue().length()) > maxLength) {
5352
errors.add(buildValidationMessage(at, "" + maxLength));
5453
}
55-
5654
return errors;
5755
}
5856

src/main/java/com/networknt/schema/MinLengthValidator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
4949
return errors;
5050
}
5151

52-
if (node.textValue().length() < minLength) {
52+
if (node.textValue().codePointCount(0, node.textValue().length()) < minLength) {
5353
errors.add(buildValidationMessage(at, "" + minLength));
5454
}
55-
5655
return errors;
5756
}
5857

src/test/resources/tests/maxLength.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
"description": "ignores non-strings",
2323
"data": 100,
2424
"valid": true
25+
},
26+
{
27+
"description": "two supplementary Unicode code points is long enough",
28+
"data": "\uD83D\uDCA9\uD83D\uDCA9",
29+
"valid": true
2530
}
2631
]
2732
}

src/test/resources/tests/minLength.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
"description": "ignores non-strings",
2323
"data": 1,
2424
"valid": true
25+
},
26+
{
27+
"description": "one supplementary Unicode code point is not long enough",
28+
"data": "\uD83D\uDCA9",
29+
"valid": false
2530
}
2631
]
2732
}

0 commit comments

Comments
 (0)