Fix utf8 cookie keys

hinted-selects
Vitaliy Filippov 2014-08-14 20:16:43 +04:00
parent b2cf9833dc
commit adf0ce5b0b
8 changed files with 17 additions and 66 deletions

View File

@ -447,7 +447,8 @@ sub cookie
# if no value is supplied, then we retrieve the
# value of the cookie, if any. For efficiency, we cache the parsed
# cookies in our state variables.
unless ( defined($value) ) {
unless (defined $value)
{
unless ($self->{'.cookies'})
{
$self->{'.cookies'} = CGI::Cookie->fetch;
@ -458,7 +459,7 @@ sub cookie
for (keys %{$self->{'.cookies'}})
{
$v = $self->{'.cookies'}->{$_}->value;
Encode::_utf8_on($_) if /[\x80-\xFFFF]/;
Encode::_utf8_on($_) if /[\x{0080}-\x{FFFF}]/;
Encode::_utf8_on($v);
push @a, $_, $v;
}

View File

@ -20,9 +20,7 @@ use strict;
package Bugzilla::Search::Saved;
use base qw(Bugzilla::Object Exporter);
our @EXPORT = qw(IsValidQueryType);
use base qw(Bugzilla::Object);
use Bugzilla::CGI;
use Bugzilla::Hook;
@ -232,8 +230,6 @@ sub remove_from_db
my $dbh = Bugzilla->dbh;
$dbh->do('DELETE FROM namedqueries WHERE id = ?', undef, $self->id);
$dbh->do('DELETE FROM namedqueries_link_in_footer WHERE namedquery_id = ?', undef, $self->id);
$dbh->do('DELETE FROM namedquery_group_map WHERE namedquery_id = ?', undef, $self->id);
if (Bugzilla->user->id == $self->userid)
{
@ -246,19 +242,6 @@ sub remove_from_db
# Complex Accessors #
#####################
sub edit_link
{
my ($self) = @_;
return $self->{edit_link} if defined $self->{edit_link};
my $params = http_decode_query($self->query);
if (!$params->{query_type} || !IsValidQueryType($params->{query_type}))
{
$params->{query_type} = 'advanced';
}
$self->{edit_link} = http_build_query($params);
return $self->{edit_link};
}
sub used_in_whine
{
my ($self) = @_;
@ -410,16 +393,6 @@ sub set_shared_with_group
$self->{shared_with_group} = $group;
}
# Validate that the query type is one we can deal with
sub IsValidQueryType
{
my ($queryType) = @_;
if (grep { $_ eq $queryType } qw(specific advanced)) {
return 1;
}
return 0;
}
1;
__END__

View File

@ -25,6 +25,7 @@ use base qw(Bugzilla::Field::Choice);
use Bugzilla::Install::Util qw(vers_cmp);
use Bugzilla::Util;
use Bugzilla::Field;
use Bugzilla::Constants;
use Bugzilla::Error;
################################

View File

@ -221,7 +221,7 @@ elsif ($action eq "convert_search") {
my ($query) = grep { $_->name eq $saved_search } @{ $user->queries };
my $url = '';
if ($query) {
my $params = http_decode_query($query->edit_link);
my $params = http_decode_query($query->query);
# These two parameters conflict with the one below.
delete $params->{$_} for ('format', 'query_format');
$url = '&' . html_quote(http_build_query($params));

View File

@ -282,48 +282,28 @@ $vars->{columnlist} = $params->{columnlist};
# Add in the defaults.
$vars->{default} = $default;
$vars->{format} = $params->{format};
# Set default page to "advanced" if none provided
if (!$params->{query_format} && !$params->{format})
{
if (defined $cgi->cookie('DEFAULTFORMAT'))
{
$params->{format} = $cgi->cookie('DEFAULTFORMAT');
}
else
{
$params->{format} = 'advanced';
}
}
$vars->{query_format} = $params->{query_format} || $params->{format};
if ($vars->{query_format} eq "create-series")
$vars->{query_format} = $params->{query_format} || $params->{format} || $cgi->cookie('DEFAULTFORMAT') || 'advanced';
if ($vars->{query_format} eq 'create-series')
{
require Bugzilla::Chart;
$vars->{category} = Bugzilla::Chart::getVisibleSeries();
}
# Set cookie to current format as default, but only if the format
# one that we should remember.
if (defined $vars->{format} && IsValidQueryType($vars->{format}))
# Set cookie to current format as default.
if ($vars->{query_format})
{
$cgi->send_cookie(
-name => 'DEFAULTFORMAT',
-value => $vars->{format},
-value => $vars->{query_format},
-expires => "Fri, 01-Jan-2038 00:00:00 GMT"
);
}
# Generate and return the UI (HTML page) from the appropriate template.
# If we submit back to ourselves (for e.g. boolean charts), we need to
# preserve format information; hence query_format taking priority over
# format.
my $format = $template->get_format(
"search/search",
$params->{query_format} || $params->{format},
$params->{ctype}
);
# preserve format information; hence query_format taking priority over format.
my $format = $template->get_format("search/search", $vars->{query_format}, $params->{ctype});
$cgi->send_header($format->{ctype});
$template->process($format->{template}, $vars)

View File

@ -100,8 +100,7 @@
[% IF q.shared_with_group.id %]&amp;sharer_id=[% user.id FILTER url_quote %][% END %]">Run</a>
</td>
<td>
<a href="query.cgi?[% q.edit_link FILTER html %]&amp;known_name=
[% q.name FILTER url_quote %]">Edit</a>
<a href="query.cgi?[% q.query | html %]&amp;known_name=[% q.name | url_quote %]">Edit</a>
</td>
<td>
[% IF q.used_in_whine OR q.used_in_checkers %]
@ -202,8 +201,7 @@
[% q.user.id FILTER url_quote %]">Run</a>
</td>
<td>
<a href="query.cgi?[% q.edit_link FILTER html %]&amp;known_name=
[% q.name FILTER url_quote %]">Edit</a>
<a href="query.cgi?[% q.query | html %]&amp;known_name=[% q.name | url_quote %]">Edit</a>
</td>
<td align="center">
<input type="checkbox"

View File

@ -27,9 +27,7 @@
[% SET checkwidths = [] %]
[%# If we resubmit to ourselves, we need to know if we are using a format. %]
[% thisformat = query_format != '' ? query_format : format %]
<input type="hidden" name="query_format" value="[% thisformat FILTER html %]">
<input type="hidden" name="query_format" value="[% query_format FILTER html %]">
[%# *** Summary *** %]

View File

@ -28,7 +28,7 @@
link => "query.cgi?format=specific" },
{ name => 'advanced', label => "Advanced Search",
link => "query.cgi?format=advanced" } ]
current_tab_name = query_format || format || "advanced"
current_tab_name = query_format
%]
[% content %]