Closed jonroler closed 11 years ago
Proposed fix is included in https://github.com/limcheekin/jquery-validation-ui/pull/25. With the fix, values now display correctly in javascript messages (instead of displaying the javascript code itself). This bug is actually pretty bad since many of the default grails error messages include the value, so people (like me) who just decide to try out this plugin with a new project will immediately encounter this bug.
Good catch! Thanks for report the issue with fix provided. This fix was just released in 1.4.4.
The fix for issue #15 added the encodeAsJavaScript() call at the end of JqueryValidationService.getMessage() in order to allow single quotes inside of message strings. This method escapes single quotes in the message which is exactly what is needed to allow arbitrary strings to be placed inside of a javascript string. However, this type of escaping can't be performed on actual javascript code, which is what is happening as a result of issue #15:
We are passing actual javascript (' + $('#name').val() + ') to get the value of the field included in the message string. However, when the single quotes are escaped, they just appear inline in the code.
The best fix I can think for this is:
This solution allows the message to be escaped for quotes as needed, and the javascript can then be added in the correct place without the escaping. The main downside to this approach is some arbitrary placeholder text has to be chosen that hopefully won't appear elsewhere in the message. I don't see any way around this, however, so we'll just have to pick something very likely to not appear in any actual message.