Skip to content

Commit

Permalink
Use ASCII JSON string for HX-Trigger http header
Browse files Browse the repository at this point in the history
HTTP headers are not supposed to contain non-ASCII characters. With this,
the generated string now is like "\u4f60\u597d" and JavaScript natively
supports it.
  • Loading branch information
sunnavy committed Jan 3, 2025
1 parent 58db4f0 commit 605c93e
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion share/html/Elements/ShowSearch
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ my $title = loc(RT::SavedSearch->EscapeDescription($search->Description), $Proce
if ( $m->request_path =~ m{^/Views/} ) {
$event{triggerChanged} = 'every ' . $refresh_seconds . 's[checkRefreshState(this)]' if $refresh_seconds;
$event{widgetTitleChanged} = $title . ( $title_raw // '' );
$r->headers_out->{'HX-Trigger'} = JSON( \%event, utf8 => 1, );
$r->headers_out->{'HX-Trigger'} = JSON( \%event, ascii => 1, );
}

my @icon_links;
Expand Down
2 changes: 1 addition & 1 deletion share/html/Helpers/AssetUpdate
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ $r->headers_out->{'HX-Trigger'} = JSON(
actionsChanged => \@results,
map { $_ => '' } @events
},
utf8 => 1,
ascii => 1,
) if @events || @results;
</%INIT>
2 changes: 1 addition & 1 deletion share/html/Helpers/QuickCreate
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ if ( $ARGS{'QuickCreateSubmit'} ) {
{
actionsChanged => \@results
},
utf8 => 1,
ascii => 1,
) if @results;

}
Expand Down
4 changes: 2 additions & 2 deletions share/html/Helpers/SavedSearchOptions
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ if ( $SavedSearchId ) {
)
],
},
utf8 => 1,
ascii => 1,
);
}
else {
RT->Logger->error(
"Unable to update SearchRefreshIntervale from $ARGS{'SearchRefreshInterval'}: $msg"
);
$r->headers_out->{'HX-Trigger'} = JSON( { actionsChanged => [$msg], }, utf8 => 1, );
$r->headers_out->{'HX-Trigger'} = JSON( { actionsChanged => [$msg], }, ascii => 1, );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion share/html/Helpers/TicketUpdate
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ $r->headers_out->{'HX-Trigger'} = JSON(
actionsChanged => \@Actions,
map { $_ => '' } @events
},
utf8 => 1,
ascii => 1,
) if @events || @Actions;

</%INIT>
2 changes: 1 addition & 1 deletion share/html/Views/Asset/Title
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ my $asset = RT::Asset->new( $session{CurrentUser} );
$asset->Load($id);

my $title = loc( "Asset #[_1]: [_2]", $asset->Id, $asset->Name || '' );
$r->headers_out->{'HX-Trigger'} = JSON( { titleChanged => $title }, utf8 => 1, );
$r->headers_out->{'HX-Trigger'} = JSON( { titleChanged => $title }, ascii => 1, );
$m->out($m->interp->apply_escapes($title, 'h'));
$m->abort;
</%INIT>
Expand Down
2 changes: 1 addition & 1 deletion share/html/Views/Ticket/Title
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ my $ticket = RT::Ticket->new( $session{CurrentUser} );
$ticket->Load($id);

my $title = loc( "#[_1]: [_2]", $ticket->Id, $ticket->Subject || '' );
$r->headers_out->{'HX-Trigger'} = JSON( { titleChanged => $title }, utf8 => 1, );
$r->headers_out->{'HX-Trigger'} = JSON( { titleChanged => $title }, ascii => 1, );
$m->out($m->interp->apply_escapes($title, 'h'));
$m->abort;
</%INIT>
Expand Down
7 changes: 3 additions & 4 deletions share/static/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,7 @@ jQuery(function() {
document.body.addEventListener('actionsChanged', function(evt) {
if ( evt.detail.value ) {
for ( const action of evt.detail.value ) {
// Need to decode action that is UTF-8 encoded
jQuery.jGrowl(decodeURIComponent(escape(action)), { themeState: 'none' });
jQuery.jGrowl(action, { themeState: 'none' });
}

const history_container = document.querySelector('.history-container');
Expand Down Expand Up @@ -854,7 +853,7 @@ jQuery(function() {
});

document.body.addEventListener('titleChanged', function(evt) {
document.title = decodeURIComponent(escape(evt.detail.value));
document.title = evt.detail.value;
});

document.body.addEventListener('triggerChanged', function(evt) {
Expand All @@ -865,7 +864,7 @@ jQuery(function() {
document.body.addEventListener('widgetTitleChanged', function(evt) {
const title = evt.detail.elt.closest('div.titlebox').querySelector('.titlebox-title a');
if ( title ) {
title.innerHTML = decodeURIComponent(escape(evt.detail.value));
title.innerHTML = evt.detail.value;
}
});

Expand Down

0 comments on commit 605c93e

Please sign in to comment.