Skip to content

Commit ab23378

Browse files
authored
Fix PatternValidator to not log for fail fast (#1106)
1 parent 12807f3 commit ab23378

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public Set<ValidationMessage> validate(ExecutionContext executionContext, JsonNo
6262
.locale(executionContext.getExecutionConfig().getLocale())
6363
.failFast(executionContext.isFailFast()).arguments(this.pattern).build());
6464
}
65-
} catch (JsonSchemaException e) {
65+
} catch (JsonSchemaException | FailFastAssertionException e) {
6666
throw e;
6767
} catch (RuntimeException e) {
6868
logger.error("Failed to apply pattern '{}' at {}: {}", this.pattern, instanceLocation, e.getMessage());
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.networknt.schema;
17+
18+
import static org.junit.jupiter.api.Assertions.*;
19+
20+
import org.junit.jupiter.api.Test;
21+
22+
import com.networknt.schema.SpecVersion.VersionFlag;
23+
24+
/**
25+
* PatternValidatorTest.
26+
*/
27+
class PatternValidatorTest {
28+
@Test
29+
void failFast() {
30+
String schemaData = "{\r\n"
31+
+ " \"type\": \"string\",\r\n"
32+
+ " \"pattern\": \"^(\\\\([0-9]{3}\\\\))?[0-9]{3}-[0-9]{4}$\"\r\n"
33+
+ "}";
34+
String inputData = "\"hello\"";
35+
JsonSchema schema = JsonSchemaFactory.getInstance(VersionFlag.V202012).getSchema(schemaData);
36+
boolean result = schema.validate(inputData, InputFormat.JSON, OutputFormat.BOOLEAN);
37+
assertFalse(result);
38+
}
39+
40+
}

0 commit comments

Comments
 (0)