Skip to content

Commit 242c3f4

Browse files
committed
feat: Recognize 'binary' and 'password' string formats as no-ops
1 parent d5f35d5 commit 242c3f4

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/main/java/com/retailsvc/http/validate/DefaultValidator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ private record FormatCheck(Predicate<String> isValid, String message) {}
8888
Map.entry("ipv4", new FormatCheck(s -> IPV4.matcher(s).matches(), "not a valid ipv4")),
8989
Map.entry("ipv6", new FormatCheck(s -> IPV6.matcher(s).matches(), "not a valid ipv6")),
9090
Map.entry("regex", new FormatCheck(DefaultValidator::isRegex, "not a valid regex")),
91-
Map.entry("byte", new FormatCheck(DefaultValidator::isByte, "not valid base64")));
91+
Map.entry("byte", new FormatCheck(DefaultValidator::isByte, "not valid base64")),
92+
Map.entry("binary", new FormatCheck(s -> true, "not valid binary")),
93+
Map.entry("password", new FormatCheck(s -> true, "not valid password")));
9294

9395
private final Function<String, Schema> refResolver;
9496
private final ConcurrentMap<String, Pattern> compiledPatterns = new ConcurrentHashMap<>();

src/test/java/com/retailsvc/http/validate/StringIntegerNumberTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,19 @@ void stringFormatByte() {
210210
.isEqualTo("format");
211211
}
212212

213+
@Test
214+
void stringFormatBinaryAcceptsAnyString() {
215+
StringSchema s = new StringSchema(Set.of(TypeName.STRING), null, null, null, "binary", null);
216+
assertThatCode(() -> v.validate("anything goes", s, "/v")).doesNotThrowAnyException();
217+
assertThatCode(() -> v.validate(" ", s, "/v")).doesNotThrowAnyException();
218+
}
219+
220+
@Test
221+
void stringFormatPasswordAcceptsAnyString() {
222+
StringSchema s = new StringSchema(Set.of(TypeName.STRING), null, null, null, "password", null);
223+
assertThatCode(() -> v.validate("anything goes", s, "/v")).doesNotThrowAnyException();
224+
}
225+
213226
@Test
214227
void stringRejectsNonString() {
215228
StringSchema s = new StringSchema(Set.of(TypeName.STRING), null, null, null, null, null);

0 commit comments

Comments
 (0)