@@ -126,7 +126,7 @@ public ValidationException(final Schema violatedSchema, final String message) {
126
126
* a (possibly empty) list of validation failures. It is used if multiple schema
127
127
* violations are found by violatedSchema
128
128
*/
129
- public ValidationException (final Schema violatedSchema , final StringBuilder pointerToViolation ,
129
+ ValidationException (final Schema violatedSchema , final StringBuilder pointerToViolation ,
130
130
final String message ,
131
131
final List <ValidationException > causingExceptions ) {
132
132
super (message );
@@ -153,6 +153,10 @@ private ValidationException(final StringBuilder pointerToViolation,
153
153
this (violatedSchema , pointerToViolation , message , causingExceptions );
154
154
}
155
155
156
+ private String escapeFragment (final String fragment ) {
157
+ return fragment .replace ("~" , "~0" ).replace ("/" , "~1" );
158
+ }
159
+
156
160
public List <ValidationException > getCausingExceptions () {
157
161
return causingExceptions ;
158
162
}
@@ -201,10 +205,11 @@ public ValidationException prepend(final String fragment) {
201
205
* @return the new {@code ViolationException} instance
202
206
*/
203
207
public ValidationException prepend (final String fragment , final Schema violatedSchema ) {
204
- Objects .requireNonNull (fragment , "fragment cannot be null" );
205
- StringBuilder newPointer = this .pointerToViolation .insert (1 , '/' ).insert (2 , fragment );
208
+ String escapedFragment = escapeFragment (
209
+ Objects .requireNonNull (fragment , "fragment cannot be null" ));
210
+ StringBuilder newPointer = this .pointerToViolation .insert (1 , '/' ).insert (2 , escapedFragment );
206
211
List <ValidationException > prependedCausingExceptions = causingExceptions .stream ()
207
- .map (exc -> exc .prepend (fragment ))
212
+ .map (exc -> exc .prepend (escapedFragment ))
208
213
.collect (Collectors .toList ());
209
214
return new ValidationException (newPointer , violatedSchema , super .getMessage (),
210
215
prependedCausingExceptions );
0 commit comments