Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix #15 Messages are now escaped properly for javascript

Add spock for testing, add ignores for intellij
  • Loading branch information...
commit 44e838e93dc1fb5c566f2fd886429e4285a0d284 1 parent ca76e39
Brian Saville bluesliverx authored
5 .gitignore
View
@@ -11,4 +11,7 @@ target-eclipse
/web-app/WEB-INF/classes
.link_to_grails_plugins
*.zip
-plugin.xml
+plugin.xml
+.idea
+*.iml
+*-plugin.xml
8 grails-app/conf/BuildConfig.groovy
View
@@ -36,10 +36,14 @@ grails.project.dependency.resolution = {
// runtime 'mysql:mysql-connector-java:5.1.5'
}
plugins {
- runtime ":hibernate:$grailsVersion"
- runtime ":jquery:1.7.2"
+ runtime ":hibernate:$grailsVersion"
+ runtime ":jquery:1.7.2"
compile ":constraints:0.6.0"
compile ":jquery-validation:1.9"
build ":tomcat:$grailsVersion"
+
+ test (':spock:0.7') {
+ export = false
+ }
}
}
4 grails-app/services/org/grails/jquery/validation/ui/JqueryValidationService.groovy
View
@@ -207,7 +207,7 @@ class JqueryValidationService {
message = messageSource.getMessage(code, [propertyName].toArray(), defaultMessage, locale)
}
- return message.encodeAsJavaScript()
+ return message.encodeAsJavaScript()
}
private String getMessage(Class validatableClass, String propertyName, def args, String constraintName, Locale locale) {
@@ -230,7 +230,7 @@ class JqueryValidationService {
code = DEFAULT_ERROR_MESSAGE_CODES_MAP[constraintName]
message = messageSource.getMessage(code, args == null ? null : args.toArray(), defaultMessage, locale)
}
- return message
+ return message.encodeAsJavaScript()
}
private String createJavaScriptConstraints(def constrainedProperty, Locale locale, String namespace, boolean forMetadata) {
44 test/unit/org/grails/jquery/validation/ui/JqueryValidationServiceSpec.groovy
View
@@ -0,0 +1,44 @@
+package org.grails.jquery.validation.ui
+
+import spock.lang.*
+import grails.test.mixin.*
+import org.springframework.context.MessageSource
+
+@TestFor(JqueryValidationService)
+public class JqueryValidationServiceSpec extends Specification {
+ def setup() {
+ String.metaClass.encodeAsJavaScript = { ->
+ org.codehaus.groovy.grails.plugins.codecs.JavaScriptCodec.encode(delegate)
+ }
+ }
+
+ @Issue("https://github.com/limcheekin/jquery-validation-ui/issues/15")
+ def "Escaped messages"() {
+ given:
+ MessageSource messageSource = Mock()
+ service.messageSource = messageSource
+
+ when:
+ def message = service.getMessage(this.class, "prop", null, "max", null)
+
+ then:
+ 1 * messageSource.getMessage("${this.class.name}.prop.max", null, null, null) >> "my 'message'"
+ 0 * _._
+ message=="my \\'message\\'"
+ }
+
+ @Issue("https://github.com/limcheekin/jquery-validation-ui/issues/15")
+ def "Escaped typeMismatch messages"() {
+ given:
+ MessageSource messageSource = Mock()
+ service.messageSource = messageSource
+
+ when:
+ def message = service.getTypeMismatchMessage(this.class, null, null, "prop", null)
+
+ then:
+ 1 * messageSource.getMessage("typeMismatch.${this.class.name}.prop", null, null, null) >> "my 'message'"
+ 0 * _._
+ message=="my \\'message\\'"
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.