File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
main/java/org/everit/json/schema
test/java/org/everit/json/schema Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -120,7 +120,11 @@ Pattern getRE2JPattern() {
120
120
}
121
121
122
122
public java .util .regex .Pattern getPattern () {
123
- return java .util .regex .Pattern .compile (pattern .toString ());
123
+ if (pattern == null ) {
124
+ return null ;
125
+ } else {
126
+ return java .util .regex .Pattern .compile (pattern .toString ());
127
+ }
124
128
}
125
129
126
130
@ Override void accept (Visitor visitor ) {
Original file line number Diff line number Diff line change 26
26
import java .util .Optional ;
27
27
28
28
import static org .everit .json .schema .TestSupport .buildWithLocation ;
29
+ import static org .junit .Assert .assertEquals ;
30
+ import static org .junit .Assert .assertNull ;
29
31
import static org .junit .Assert .assertTrue ;
30
32
31
33
public class StringSchemaTest {
@@ -166,4 +168,19 @@ public void requiresString_nullable() {
166
168
Schema subject = StringSchema .builder ().requiresString (true ).nullable (true ).build ();
167
169
subject .validate (JSONObject .NULL );
168
170
}
171
+
172
+ @ Test
173
+ public void getConvertedPattern () {
174
+ StringSchema subject = StringSchema .builder ().pattern ("my\\ \\ /[p]a[tt]ern" ).build ();
175
+ assertEquals ("my\\ \\ /[p]a[tt]ern" , subject .getRE2JPattern ().toString ());
176
+ assertEquals ("my\\ \\ /[p]a[tt]ern" , subject .getPattern ().toString ());
177
+ }
178
+
179
+ @ Test
180
+ public void getConvertedNullPattern () {
181
+ StringSchema subject = StringSchema .builder ().build ();
182
+ assertNull (subject .getRE2JPattern ());
183
+ assertNull (subject .getPattern ());
184
+ }
185
+
169
186
}
You can’t perform that action at this time.
0 commit comments