From e49a31df6ac73fd48b7799b2359cde73eaee041f Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 12 Aug 2022 19:47:25 -0500 Subject: [PATCH] Avoid double-quotes in field error messages JS code --- tailbone/forms/core.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tailbone/forms/core.py b/tailbone/forms/core.py index bd939272..ac17c1b4 100644 --- a/tailbone/forms/core.py +++ b/tailbone/forms/core.py @@ -904,10 +904,19 @@ class Form(object): # show errors if present error_messages = self.get_error_messages(field) if error_messages: + + # TODO: this surely can't be what we ought to do + # here..? seems like we must pass JS but not JSON, + # sort of, so we custom-write the JS code to ensure + # single instead of double quotes delimit strings + # within the code. + message = '[{}]'.format(', '.join([ + "'{}'".format(msg.replace("'", r"\'")) + for msg in error_messages])) + attrs.update({ 'type': 'is-danger', - # ':message': self.messages_json(error_messages), - ':message': error_messages, + ':message': message, }) # merge anything caller provided