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 <baptiste.wojtkowski@biblibre.com>
Signed-off-by: David Cook <dcook@prosentient.com.au>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Jonathan Druart 2025-01-27 09:56:30 +01:00 committed by Paul Derscheid
parent 755e20839b
commit 51c780583f
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
1 changed files with 17 additions and 16 deletions

View File

@ -193,19 +193,20 @@ if ($is_ajax) {
}
$js_reply .= "\n\t]";
}
my $err_string = '';
if (scalar @errors) {
$err_string = ",\n\talerts: ["; # open response_function
my $i = 1;
foreach (@errors) {
my $key = (keys %$_)[0];
$err_string .= "\n\t\t KOHA.Tags.tag_message.$key(\"" . $_->{$key} . '")';
if($i < scalar @errors){ $err_string .= ","; }
$i++;
}
$err_string .= "\n\t]\n"; # close response_function
}
my $err_string = '';
if ( scalar @errors ) {
$err_string = ",\n\talerts: ["; # open response_function
my $i = 1;
foreach (@errors) {
my $key = ( keys %$_ )[0];
( 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++;
}
$err_string .= "\n\t]\n"; # close response_function
}
# Add per-biblionumber results for use on results page
my $js_perbib = "";
@ -216,8 +217,9 @@ if ($is_ajax) {
my $i = 0;
foreach (@{$bibResult->{errors}}) {
$js_bibres .= "," if ($i);
my $key = (keys %$_)[0];
$js_bibres .= "\n\t\t\t KOHA.Tags.tag_message.$key(\"" . $_->{$key} . '")';
my $key = ( keys %$_ )[0];
( 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}";
@ -377,4 +379,3 @@ response = {
};
=cut