[Bps-public-commit] rt-extension-formtools branch avoid-long-urls created. 1.01-11-g7ab1422
BPS Git Server
git at git.bestpractical.com
Wed Feb 7 21:39:54 UTC 2024
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt-extension-formtools".
The branch, avoid-long-urls has been created
at 7ab142254594ea7dd8b700f4035a80e88e6953da (commit)
- Log -----------------------------------------------------------------
commit 7ab142254594ea7dd8b700f4035a80e88e6953da
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed Feb 7 16:33:47 2024 -0500
Avoid long redirect URLs from the Back button
When user clicks Back button, we redirect to previous page's URL that
contains all submitted data, which might exceed the length limit of URL and
thus cause a 500 error with logs like:
Premature end of script headers: rt-server.fcgi
This commit shortens the URL when it happens to avoid this error.
Note that unlike $DECODED_ARGS, $m->request_args doesn't contain expanded
args in shortner, so here we switch to $DECODED_ARGS.
diff --git a/html/FormTools/Field b/html/FormTools/Field
index 60a3c5b..fb205a2 100644
--- a/html/FormTools/Field
+++ b/html/FormTools/Field
@@ -94,11 +94,9 @@ if ( RT::Extension::FormTools::is_core_field($name) ) {
);
}
-my $request_args = $m->request_args();
+my $request_args = $DECODED_ARGS;
if ( $render_as !~ /readonly/ ) {
- my $request_args = $m->request_args();
-
if ( $field_type eq 'core' && exists $request_args->{$name} ) {
$default = $request_args->{$name};
}
diff --git a/html/FormTools/Form b/html/FormTools/Form
index 8dca906..f5ca591 100644
--- a/html/FormTools/Form
+++ b/html/FormTools/Form
@@ -28,7 +28,7 @@ my $header_component = $self_service ? '/SelfService/Elements/Header' : '/Elemen
my %cfs = map { $_ => 1} @{ $m->notes('cfs_on_page') || [] };
my %core_fields = map { $_ => 1} @{ $m->notes('core_fields_on_page') || [] };
-my %request_args = $m->request_args;
+my %request_args = %$DECODED_ARGS;
my @results;
my $real_next = delete $request_args{_form_tools_next};
@@ -133,7 +133,7 @@ $next_for_validation ||= $m->caller(1)->path;
% next if $forbid_persisting->{$key};
% next if ($key eq 'user' or $key eq 'pass');
% next if $key eq 'Submit'; # No need to pass through "Next" button value
-% next if $key =~ /^(?:validation|validation_ok|next_for_validation)$/;
+% next if $key =~ /^(?:validation|validation_ok|next_for_validation|sc)$/;
<input type="hidden" name="<%$key%>" value="<%$val%>" />
% }
% }
diff --git a/html/FormTools/ShowChoices b/html/FormTools/ShowChoices
index 8e07d15..ccaed49 100644
--- a/html/FormTools/ShowChoices
+++ b/html/FormTools/ShowChoices
@@ -1,7 +1,7 @@
<%init>
my $queue = $m->notes('queue');
-my %all_fields = $m->request_args;
+my %all_fields = %$DECODED_ARGS;
</%init>
% foreach my $field (keys %all_fields) {
% next if $field =~ /-Magic/;
diff --git a/html/Forms/dhandler b/html/Forms/dhandler
index 674929d..ca9f744 100644
--- a/html/Forms/dhandler
+++ b/html/Forms/dhandler
@@ -302,6 +302,15 @@ if ( $ARGS{Back} and $ARGS{Back} eq 'Back' ) {
}
}
+ # In case the URL is too long
+ if ( HTML::Mason::Commands->can('ShortenQuery') ) {
+ my $url = RT->Config->Get('WebURL') . $base_path . $form_name . '/' . $back_page;
+ my $query = $m->comp( '/Elements/QueryString', %ARGS );
+ if ( length "$url?$query" >= 2000 ) {
+ %ARGS = ShortenQuery(%ARGS);
+ }
+ }
+
# Redirect to the previous page
MaybeRedirectForResults(
Path => $base_path . $form_name . '/' . $back_page,
-----------------------------------------------------------------------
hooks/post-receive
--
rt-extension-formtools
More information about the Bps-public-commit
mailing list