Author: hardy.ferentschik
Date: 2009-06-22 10:22:20 -0400 (Mon, 22 Jun 2009)
New Revision: 16857
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolator.java
Log:
HV-174 Made sure that replacement string are properly escaped
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolator.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolator.java 2009-06-22
14:21:28 UTC (rev 16856)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolator.java 2009-06-22
14:22:20 UTC (rev 16857)
@@ -199,7 +199,7 @@
parameter, bundle, locale, recurse
);
- matcher.appendReplacement( sb, resolvedParameterValue );
+ matcher.appendReplacement( sb, escapeMetaCharacters( resolvedParameterValue ) );
}
matcher.appendTail( sb );
return sb.toString();
@@ -213,7 +213,7 @@
String parameter = matcher.group( 1 );
Object variable = annotationParameters.get( removeCurlyBrace( parameter ) );
if ( variable != null ) {
- resolvedParameterValue = variable.toString();
+ resolvedParameterValue = escapeMetaCharacters( variable.toString() );
}
else {
resolvedParameterValue = message;
@@ -269,4 +269,15 @@
}
return bundle;
}
+
+ /**
+ * @param s The string in which to replace the meta characters '$' and
'\'.
+ *
+ * @return A string where meta characters relevant for {@link Matcher#appendReplacement}
are escaped.
+ */
+ private String escapeMetaCharacters(String s) {
+ String escapedString = s.replace( "\\", "\\\\" );
+ escapedString = escapedString.replace( "$", "\\$" );
+ return escapedString;
+ }
}
Show replies by date