Skip to content

Commit

Permalink
HV-1669 Only enable the SafeHtml constraint if jsoup is in the classpath
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Dec 5, 2018
1 parent 3dfc59b commit 76cec77
Showing 1 changed file with 8 additions and 1 deletion.
Expand Up @@ -307,6 +307,7 @@ public class ConstraintHelper {
private static final Log LOG = LoggerFactory.make( MethodHandles.lookup() );
private static final String JODA_TIME_CLASS_NAME = "org.joda.time.ReadableInstant";
private static final String JAVA_MONEY_CLASS_NAME = "javax.money.MonetaryAmount";
private static final String JSOUP_CLASS_NAME = "org.jsoup.Jsoup";

@Immutable
private final Map<Class<? extends Annotation>, List<? extends ConstraintValidatorDescriptor<?>>> builtinConstraints;
Expand Down Expand Up @@ -678,7 +679,9 @@ public ConstraintHelper() {
putConstraint( tmpConstraints, PESEL.class, PESELValidator.class );
putConstraint( tmpConstraints, Range.class );
putConstraint( tmpConstraints, REGON.class, REGONValidator.class );
putConstraint( tmpConstraints, SafeHtml.class, SafeHtmlValidator.class );
if ( isJsoupInClasspath() ) {
putConstraint( tmpConstraints, SafeHtml.class, SafeHtmlValidator.class );
}
putConstraint( tmpConstraints, ScriptAssert.class, ScriptAssertValidator.class );
putConstraint( tmpConstraints, TituloEleitoral.class );
putConstraint( tmpConstraints, UniqueElements.class, UniqueElementsValidator.class );
Expand Down Expand Up @@ -994,6 +997,10 @@ private static boolean isJavaMoneyInClasspath() {
return isClassPresent( JAVA_MONEY_CLASS_NAME );
}

private static boolean isJsoupInClasspath() {
return isClassPresent( JSOUP_CLASS_NAME );
}

/**
* Returns the default validators for the given constraint type.
*
Expand Down

0 comments on commit 76cec77

Please sign in to comment.