-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable message interpolation in ConstraintViolations by default (#3208)
Disable message interpolation in ConstraintViolations by default but allow enabling it explicitly with `SelfValidating#escapeExpressions()`. Additionally, `ConstraintViolations` now provides a set of methods which take a map of message parameters for interpolation. The message parameters will be escaped by default. Refs #3153 Refs #3157
- Loading branch information
Showing
5 changed files
with
222 additions
and
31 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
dropwizard-validation/src/main/java/io/dropwizard/validation/InterpolationHelper.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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * Hibernate Validator, declare and validate application constraints | ||
| * | ||
| * License: Apache License, Version 2.0 | ||
| * See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | ||
| */ | ||
| package io.dropwizard.validation; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| /** | ||
| * Utilities used for message interpolation. | ||
| * | ||
| * @author Guillaume Smet | ||
| * @since 2.0.3 | ||
| */ | ||
| public final class InterpolationHelper { | ||
|
|
||
| public static final char BEGIN_TERM = '{'; | ||
| public static final char END_TERM = '}'; | ||
| public static final char EL_DESIGNATOR = '$'; | ||
| public static final char ESCAPE_CHARACTER = '\\'; | ||
|
|
||
| private static final Pattern ESCAPE_MESSAGE_PARAMETER_PATTERN = Pattern.compile("([\\" + ESCAPE_CHARACTER + BEGIN_TERM + END_TERM + EL_DESIGNATOR + "])"); | ||
|
|
||
| private InterpolationHelper() { | ||
| } | ||
|
|
||
| @Nullable | ||
| public static String escapeMessageParameter(@Nullable String messageParameter) { | ||
| if (messageParameter == null) { | ||
| return null; | ||
| } | ||
| return ESCAPE_MESSAGE_PARAMETER_PATTERN.matcher(messageParameter).replaceAll(Matcher.quoteReplacement(String.valueOf(ESCAPE_CHARACTER)) + "$1"); | ||
| } | ||
| } |
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
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
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
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