From 037d02ff90c0c07f22a5ef2c1bb52e2be653dac6 Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Fri, 13 Apr 2018 15:34:30 +0200 Subject: [PATCH] TT#35715 ensure that next_page() retains original query params * it is important that next_page() retains the original query params via links->next->href as otherwise that leads to unpredicted results and no filtering Change-Id: I8606a9fa03758eb214c7aa38958f158f2cc1a16e (cherry picked from commit bb51c3ee49805c2d9f50386ef0d41133c51e52fc) (cherry picked from commit 2d262bc34d4742e0108c8299ce9c8260738dac5b) --- lib/NGCP/API/Client.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/NGCP/API/Client.pm b/lib/NGCP/API/Client.pm index 1ad78c6..1e31d55 100644 --- a/lib/NGCP/API/Client.pm +++ b/lib/NGCP/API/Client.pm @@ -100,6 +100,8 @@ sub request { sub next_page { my ($self, $uri) = @_; + (my $params = $uri) =~ s/^[^?]+\?//; + unless ($self->{_ua}) { ($self->{_ua},$self->{_urlbase}) = $self->_create_ua($uri); $self->{_collection_url} = sprintf "https://%s%s%spage=1&rows=%d", $self->{_urlbase}, @@ -115,8 +117,12 @@ sub next_page { my $res = NGCP::API::Client::Result->new($self->{_ua}->request($req)); undef $self->{_collection_url}; - if ('HASH' eq ref (my $data = $res->as_hash())) { + + my $data = $res->as_hash(); + if ($data && ref($data) eq 'HASH') { $uri = $data->{_links}->{next}->{href}; + return $res unless $uri && $uri =~ /rows/; + $uri .= '&'.$params if $params && $uri !~ /\Q$params\E/; $self->{_collection_url} = $self->_get_url($self->{_urlbase},$uri) if $uri; }