Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/controllers/cameras/socs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,15 @@ def apply_permalink_to(camera)
# copied, and it is applied whether or not the link carried one.
camera.camera_mac_address = params[:mac].to_s.downcase.gsub('-', ':')

# present?, not just presence of the key. A permanent link carries every
# field whether or not it has a value, so `?...&ver=&sd=` is what a link
# built from a camera with no edition chosen looks like -- and the menu
# can produce exactly that, since allowedEditions falls back to '' when a
# chip has nothing published for it. Treating the empty string as an
# answer blanked the dropdown; blank means "not specified", so the
# constructor default stands.
PERMALINK_FIELDS.each do |key, field|
camera.public_send("#{field}=", params[key]) if params[key]
camera.public_send("#{field}=", params[key]) if params[key].present?
end
end

Expand Down
26 changes: 26 additions & 0 deletions test/controllers/socs_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,32 @@ def assert_form_reopened_on(chip, edition)
end
end

# A permanent link names every field whether or not it has a value, so
# `&ver=` is what a link built with no edition chosen looks like -- and the
# menu produces exactly that, because allowedEditions falls back to '' for a
# chip with nothing published. OpenIPC/firmware#1912 carries a real one.
# Reading the empty string as an answer left the dropdown with nothing
# selected at all.
def assert_blank_edition_key_ignored(key, model)
soc = instructable_soc(model)

with_release_index(*every_edition_for(soc)) do
get "/cameras/vendors/#{soc.vendor.to_param}/socs/#{soc.to_param}" \
"?mac=aa-bb-cc-dd-ee-ff&cip=10.0.0.5&sip=10.0.0.1&net=both&rom=nor16m&#{key}=&sd=sd"

assert_response :success
assert_match %(<option selected="selected" value="lite">), response.body
end
end

test 'an empty var= in a link is no edition rather than a blank one' do
assert_blank_edition_key_ignored('var', 'TS3516EVC00')
end

test 'an empty ver= in a link is no edition rather than a blank one' do
assert_blank_edition_key_ignored('ver', 'TS3516EVC10')
end

test 'a link shared before the spelling was fixed still carries its edition' do
soc = instructable_soc('TS3516EV900')

Expand Down
Loading