File tree Expand file tree Collapse file tree 2 files changed +32
-6
lines changed
main/java/com/networknt/schema
test/java/com/networknt/schema Expand file tree Collapse file tree 2 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -114,14 +114,16 @@ public static SchemaLocation of(String iri) {
114
114
if ("#" .equals (iri )) {
115
115
return DOCUMENT ;
116
116
}
117
- String [] iriParts = iri .split ("#" );
118
117
AbsoluteIri absoluteIri = null ;
119
118
JsonNodePath fragment = JSON_POINTER ;
120
- if (iriParts .length > 0 ) {
121
- absoluteIri = AbsoluteIri .of (iriParts [0 ]);
122
- }
123
- if (iriParts .length > 1 ) {
124
- fragment = Fragment .of (iriParts [1 ]);
119
+ int index = iri .indexOf ('#' );
120
+ if (index == -1 ) {
121
+ absoluteIri = AbsoluteIri .of (iri );
122
+ } else {
123
+ absoluteIri = AbsoluteIri .of (iri .substring (0 , index ));
124
+ if (iri .length () > index + 1 ) {
125
+ fragment = Fragment .of (iri .substring (index + 1 ));
126
+ }
125
127
}
126
128
return new SchemaLocation (absoluteIri , fragment );
127
129
}
Original file line number Diff line number Diff line change @@ -231,4 +231,28 @@ void hashCodeEquals() {
231
231
SchemaLocation .of ("https://example.com/schemas/address/#street_address" ).hashCode ());
232
232
}
233
233
234
+ @ Test
235
+ void hashInFragment () {
236
+ SchemaLocation location = SchemaLocation .of ("https://example.com/example.yaml#/paths/~1subscribe/post/callbacks/myEvent/{request.body#~1callbackUrl}/post/requestBody/content/application~1json/schema" );
237
+ assertEquals ("/paths/~1subscribe/post/callbacks/myEvent/{request.body#~1callbackUrl}/post/requestBody/content/application~1json/schema" , location .getFragment ().toString ());
238
+ }
239
+
240
+ @ Test
241
+ void trailingHash () {
242
+ SchemaLocation location = SchemaLocation .of ("https://example.com/example.yaml#" );
243
+ assertEquals ("" , location .getFragment ().toString ());
244
+ }
245
+
246
+ @ Test
247
+ void equalsEqualsNoFragment () {
248
+ assertEquals (SchemaLocation .of ("https://example.com/example.yaml#" ),
249
+ SchemaLocation .of ("https://example.com/example.yaml" ));
250
+ }
251
+
252
+ @ Test
253
+ void equalsEqualsNoFragmentToString () {
254
+ assertEquals (SchemaLocation .of ("https://example.com/example.yaml#" ).toString (),
255
+ SchemaLocation .of ("https://example.com/example.yaml" ).toString ());
256
+ }
257
+
234
258
}
You can’t perform that action at this time.
0 commit comments