@@ -18,6 +18,7 @@ use Bugzilla::Error;
1818use Bugzilla::Util;
1919use Bugzilla::Hook;
2020use Bugzilla::Search::Recent;
21+ use Bugzilla::Install::Util qw( i_am_persistent) ;
2122
2223use File::Basename;
2324
@@ -34,8 +35,7 @@ sub _init_bz_cgi_globals {
3435
3536 # We don't precompile any functions here, that's done specially in
3637 # mod_perl code.
37- $invocant -> _setup_symbols(qw( :no_xhtml :oldstyle_urls :private_tempfiles
38- :unique_headers) );
38+ $invocant -> _setup_symbols(qw( :no_xhtml :oldstyle_urls :unique_headers :utf8) );
3939}
4040
4141BEGIN { __PACKAGE__ -> _init_bz_cgi_globals() if i_am_cgi(); }
@@ -44,9 +44,7 @@ sub new {
4444 my ($invocant , @args ) = @_ ;
4545 my $class = ref ($invocant ) || $invocant ;
4646
47- # Under mod_perl, CGI's global variables get reset on each request,
48- # so we need to set them up again every time.
49- $class -> _init_bz_cgi_globals() if $ENV {MOD_PERL };
47+ $class -> _init_bz_cgi_globals() if i_am_persistent();
5048
5149 my $self = $class -> SUPER::new(@args );
5250
@@ -65,18 +63,11 @@ sub new {
6563 # Path-Info is of no use for Bugzilla and interacts badly with IIS.
6664 # Moreover, it causes unexpected behaviors, such as totally breaking
6765 # the rendering of pages.
68- if (my $path_info = $self -> path_info) {
66+ if ($self -> script_name && $self -> path_info) {
6967 my @whitelist = (" rest.cgi" );
7068 Bugzilla::Hook::process(' path_info_whitelist' , { whitelist => \@whitelist });
7169 if (!grep ($_ eq $script , @whitelist )) {
72- # IIS includes the full path to the script in PATH_INFO,
73- # so we have to extract the real PATH_INFO from it,
74- # else we will be redirected outside Bugzilla.
75- my $script_name = $self -> script_name;
76- $path_info =~ s / ^\Q $script_name\E // ;
77- if ($script_name && $path_info ) {
78- print $self -> redirect($self -> url(-path => 0, -query => 1));
79- }
70+ print $self -> redirect($self -> url(-path => 0, -query => 1));
8071 }
8172 }
8273
@@ -117,7 +108,7 @@ sub canonicalise_query {
117108
118109 # Reconstruct the URL by concatenating the sorted param=value pairs
119110 my @parameters ;
120- foreach my $key (sort ($self -> param ())) {
111+ foreach my $key (sort ($self -> multi_param ())) {
121112 # Leave this key out if it's in the exclude list
122113 next if grep { $_ eq $key } @exclude ;
123114
@@ -127,7 +118,7 @@ sub canonicalise_query {
127118
128119 my $esc_key = url_quote($key );
129120
130- foreach my $value ($self -> param ($key )) {
121+ foreach my $value ($self -> multi_param ($key )) {
131122 # Omit params with an empty value
132123 if (defined ($value ) && $value ne ' ' ) {
133124 my $esc_value = url_quote($value );
@@ -143,7 +134,7 @@ sub canonicalise_query {
143134sub clean_search_url {
144135 my $self = shift ;
145136 # Delete any empty URL parameter.
146- my @cgi_params = $self -> param ;
137+ my @cgi_params = $self -> multi_param() ;
147138
148139 foreach my $param (@cgi_params ) {
149140 if (defined $self -> param($param ) && $self -> param($param ) eq ' ' ) {
@@ -252,23 +243,12 @@ sub check_etag {
252243# Have to add the cookies in.
253244sub multipart_start {
254245 my $self = shift ;
255-
256- my %args = @_ ;
257-
258- # CGI.pm::multipart_start doesn't honour its own charset information, so
259- # we do it ourselves here
260- if (defined $self -> charset() && defined $args {-type}) {
261- # Remove any existing charset specifier
262- $args {-type} =~ s / ;.*$// ;
263- # and add the specified one
264- $args {-type} .= ' ; charset=' . $self -> charset();
265- }
266-
267- my $headers = $self -> SUPER::multipart_start(%args );
246+ # We have to explicitly pass the charset.
247+ my $headers = $self -> SUPER::multipart_start(@_ , -charset => $self -> charset());
268248 # Eliminate the one extra CRLF at the end.
269249 $headers =~ s / $CGI::CRLF$// ;
270250 # Add the cookies. We have to do it this way instead of
271- # passing them to multpart_start , because CGI.pm's multipart_start
251+ # passing them to multipart_start , because CGI.pm's multipart_start
272252 # doesn't understand a '-cookie' argument pointing to an arrayref.
273253 foreach my $cookie (@{$self -> {Bugzilla_cookie_list }}) {
274254 $headers .= " Set-Cookie: ${cookie}${CGI::CRLF} " ;
@@ -366,11 +346,15 @@ sub header {
366346
367347sub param {
368348 my $self = shift ;
369- local $CGI::LIST_CONTEXT_WARN = 0;
349+
350+ my @caller = caller (0);
351+ if (wantarray && $caller [0] ne ' CGI' ) {
352+ warn ' Illegal call to $cgi->param in list context from ' . $caller [0];
353+ }
370354
371355 # When we are just requesting the value of a parameter...
372356 if (scalar (@_ ) == 1) {
373- my @result = $self -> SUPER::param (@_ );
357+ my @result = $self -> SUPER::multi_param (@_ );
374358
375359 # Also look at the URL parameters, after we look at the POST
376360 # parameters. This is to allow things like login-form submissions
@@ -381,9 +365,6 @@ sub param {
381365 @result = $self -> url_param(@_ );
382366 }
383367
384- # Fix UTF-8-ness of input parameters.
385- @result = map { _fix_utf8($_ ) } @result ;
386-
387368 return wantarray ? @result : $result [0];
388369 }
389370 # And for various other functions in CGI.pm, we need to correctly
@@ -392,13 +373,13 @@ sub param {
392373 elsif (!scalar (@_ ) && $self -> request_method
393374 && $self -> request_method eq ' POST' )
394375 {
395- my @post_params = $self -> SUPER::param ;
376+ my @post_params = $self -> SUPER::multi_param() ;
396377 my @url_params = $self -> url_param;
397378 my %params = map { $_ => 1 } (@post_params , @url_params );
398379 return keys %params ;
399380 }
400381
401- return $self -> SUPER::param (@_ );
382+ return $self -> SUPER::multi_param (@_ );
402383}
403384
404385sub url_param {
@@ -409,13 +390,6 @@ sub url_param {
409390 return $self -> SUPER::url_param(@_ );
410391}
411392
412- sub _fix_utf8 {
413- my $input = shift ;
414- # The is_utf8 is here in case CGI gets smart about utf8 someday.
415- utf8::decode($input ) if defined $input && !ref $input && !utf8::is_utf8($input );
416- return $input ;
417- }
418-
419393sub should_set {
420394 my ($self , $param ) = @_ ;
421395 my $set = (defined $self -> param($param )
@@ -609,21 +583,12 @@ sub STORE {
609583sub FETCH {
610584 my ($self , $param ) = @_ ;
611585 return $self if $param eq ' CGI' ; # CGI.pm did this, so we do too.
612- my @result = $self -> param ($param );
586+ my @result = $self -> multi_param ($param );
613587 return undef if !scalar (@result );
614588 return $result [0] if scalar (@result ) == 1;
615589 return \@result ;
616590}
617591
618- # For the Vars TIEHASH interface: the normal CGI.pm DELETE doesn't return
619- # the value deleted, but Perl's "delete" expects that value.
620- sub DELETE {
621- my ($self , $param ) = @_ ;
622- my $value = $self -> FETCH($param );
623- $self -> delete ($param );
624- return $value ;
625- }
626-
6275921;
628593
629594__END__
0 commit comments