diff --git a/app/controllers/cameras/socs_controller.rb b/app/controllers/cameras/socs_controller.rb index b9492ed..1d9b4e8 100644 --- a/app/controllers/cameras/socs_controller.rb +++ b/app/controllers/cameras/socs_controller.rb @@ -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 diff --git a/test/controllers/socs_controller_test.rb b/test/controllers/socs_controller_test.rb index d3eec78..7bbb01b 100644 --- a/test/controllers/socs_controller_test.rb +++ b/test/controllers/socs_controller_test.rb @@ -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 %(