diff --git a/config/routes.rb b/config/routes.rb index d8b5962c..334e1c1c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -217,12 +217,12 @@ # Journal names routinely contain periods (e.g. "Cryptogamie. Algologie"), # which Rails' default segment matcher excludes to leave room for format # detection (":journal.json"), so it silently truncates them instead. - # Constrain :journal to swallow everything but a real trailing ".json"/ - # ".html", so a literal period in the name is matched as part of :journal - # while an actual format suffix is still recognized. + # Journal names can also contain slashes. Constrain :journal to swallow + # everything but a real trailing ".json"/".html", so literal punctuation + # is matched as part of :journal while a format suffix is still recognized. resources( :journals, only: %i[index show], param: :journal, - constraints: { journal: /[^\/]+?/, format: /json|html/ } + constraints: { journal: /.+?/, format: /json|html/ } ) # Publications diff --git a/test/controllers/journals_controller_test.rb b/test/controllers/journals_controller_test.rb index bbf5f6c3..9a61b8b8 100644 --- a/test/controllers/journals_controller_test.rb +++ b/test/controllers/journals_controller_test.rb @@ -1,6 +1,15 @@ require 'test_helper' class JournalsControllerTest < ActionDispatch::IntegrationTest + test 'journal names with slashes generate links and resolve to the full name' do + journal = "Annales de l'Institut Pasteur / Microbiologie" + + path = journal_path(journal) + get(path) + assert_response :success + assert_equal journal, @request.params[:journal] + end + test 'show resolves a journal name with an embedded period, untruncated' do get('/journals/' + ERB::Util.url_encode('Cryptogamie. Algologie')) assert_response :success