Skip to content

Commit 5d59333

Browse files
authored
Support getting pages with empty ?url param (#1293)
This treats `?url=` and `?url=*` querystrings the same as not specifying `url` at all. That’s a slight improvement for the second case and makes the first case work (previously it guaranteed no results, since no URL can match the empty string!).
1 parent 77db9ff commit 5d59333

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

app/controllers/api/v0/pages_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def page_collection
165165
}.compact)
166166
end
167167

168-
if params[:url]
168+
if params[:url].present? && params[:url] != '*'
169169
query = params[:url]
170170
collection = collection.joins(:urls)
171171
if query.include? '*'

test/controllers/api/v0/pages_controller_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,28 @@ def chunk_size_in_url(url)
117117
'Results included pages not matching filtered URL'
118118
end
119119

120+
test 'filtering URL with empty string is the same as no filter' do
121+
sign_in users(:alice)
122+
all_ids = Page.all.pluck(:uuid).sort
123+
get '/api/v0/pages/?url='
124+
body_json = JSON.parse @response.body
125+
ids = body_json['data'].pluck('uuid').sort
126+
127+
assert_equal all_ids, ids
128+
assert_not ids.empty?
129+
end
130+
131+
test 'filtering URL with "*" is the same as no filter' do
132+
sign_in users(:alice)
133+
all_ids = Page.all.pluck(:uuid).sort
134+
get '/api/v0/pages/?url=*'
135+
body_json = JSON.parse @response.body
136+
ids = body_json['data'].pluck('uuid').sort
137+
138+
assert_equal all_ids, ids
139+
assert_not ids.empty?
140+
end
141+
120142
test 'can filter pages by version source_type' do
121143
sign_in users(:alice)
122144
get api_v0_pages_path(source_type: 'pagefreezer')

0 commit comments

Comments
 (0)