Skip to content

Commit

Permalink
Escape Java EL in validation message before interpolation (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
karaimin authored Nov 30, 2020
1 parent 8a09b8c commit 413b5d7
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@

package com.sap.scimono.entity.schema.validation;

import java.util.regex.Pattern;

import javax.validation.ConstraintValidatorContext;

class ValidationUtil {
private static final Pattern EXPRESSION_LANGUAGE_CHARACTERS = Pattern.compile("([${}])");

public static void interpolateErrorMessage(ConstraintValidatorContext context, String errorMessage) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(errorMessage).addConstraintViolation();
context.buildConstraintViolationWithTemplate(escapeExpressionLanguage(errorMessage)).addConstraintViolation();
}

private static String escapeExpressionLanguage(String text) {
return EXPRESSION_LANGUAGE_CHARACTERS.matcher(text).replaceAll( "\\\\$1" );
}

}

0 comments on commit 413b5d7

Please # to comment.