-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Escape Java EL in validation message before interpolation (#117)
- Loading branch information
Showing
1 changed file
with
8 additions
and
1 deletion.
There are no files selected for viewing
9 changes: 8 additions & 1 deletion
9
scimono-server/src/main/java/com/sap/scimono/entity/schema/validation/ValidationUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ); | ||
} | ||
|
||
} |