Skip to content

Commit

Permalink
Include paging params in list of good keys
Browse files Browse the repository at this point in the history
  • Loading branch information
autarch committed Jul 4, 2014
1 parent f72472d commit fc71dfe
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/VegGuide/Role/Controller/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -111,31 +111,47 @@ sub _extra_search_params {
return $extra->($c);
}

my %paging_keys = map { $_ => 1 } qw(
order_by
sort_order
page
limit
);

sub _search_from_request {
my $self = shift;
my $c = shift;
my $path = shift;
my $class = shift;
my $extra = shift;

my %path_params = $self->_params_from_path_query($path);
my %good_keys = (
%paging_keys,
map { $_ => 1 } $class->SearchKeys(),
);

my %good_keys = map { $_ => 1 } $class->SearchKeys();
my %path_params = $self->_params_from_path_query($path);
if ( any { !$good_keys{$_} } keys %path_params ) {
$c->redirect_and_detach( uri( path => '/' ), 301 );
}

my %request_params = %{ $c->request()->parameters() };
if ( any { !$good_keys{$_} } keys %request_params ) {
$c->redirect_and_detach( uri( path => '/' ), 301 );
}

my %p = (
%path_params,
%{ $c->request()->query_parameters() },
%request_params,
%{ $extra || {} },
);

$self->_redirect_on_bad_request( $c, $class, %p );

delete $p{$_} for grep {/^possible/} keys %p;
delete $p{$_} for grep { /^possible/ } keys %p;
delete @p{qw( order_by sort_order page limit )};
delete $p{'ie-hack'};

# used for forcing a JSON response
delete $p{'content-type'};

Expand Down

0 comments on commit fc71dfe

Please sign in to comment.