From 795dc3ffd91c3f33c302a7ba2666711cc5c0e9db Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 27 Jan 2025 09:56:30 +0100 Subject: [PATCH] Bug 38969: Prevent JS error when adding tags with quote at the OPAC Uncaught SyntaxError: missing ) after argument list There are way more to fix in this controller... Signed-off-by: Baptiste Wojtkowski --- opac/opac-tags.pl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/opac/opac-tags.pl b/opac/opac-tags.pl index 7a65538c..a1d0627a 100755 --- a/opac/opac-tags.pl +++ b/opac/opac-tags.pl @@ -202,7 +202,8 @@ if ($is_ajax) { my $i = 1; foreach (@errors) { my $key = ( keys %$_ )[0]; - $err_string .= "\n\t\t KOHA.Tags.tag_message.$key(\"" . $_->{$key} . '")'; + ( my $quote_escaped = $_->{$key} ) =~ s|"|\\"|g; + $err_string .= sprintf qq{\n\t\t KOHA.Tags.tag_message.%s("%s")}, $key, $quote_escaped; if ( $i < scalar @errors ) { $err_string .= ","; } $i++; } @@ -219,7 +220,8 @@ if ($is_ajax) { foreach ( @{ $bibResult->{errors} } ) { $js_bibres .= "," if ($i); my $key = ( keys %$_ )[0]; - $js_bibres .= "\n\t\t\t KOHA.Tags.tag_message.$key(\"" . $_->{$key} . '")'; + ( my $quote_escaped = $_->{$key} ) =~ s|"|\\"|g; + $js_bibres .= sprintf qq{\n\t\t\t KOHA.Tags.tag_message.%s("%s")}, $key, $quote_escaped; $i++; } $js_bibres .= "\n\t\t]\n\t}"; @@ -382,4 +384,3 @@ response = { }; =cut - -- 2.30.2