From fffca4234c8dc5c7521d56bf1921951c6e2b9fcc Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Mon, 15 Jul 2019 16:39:27 +0530 Subject: [PATCH] FIX: allow ampersand in site_texts routes --- config/routes.rb | 12 ++++++------ .../admin/site_texts_controller_spec.rb | 18 +++++++++++++++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 1cfc99dc3fe..44a26637ffc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -221,12 +221,12 @@ Discourse::Application.routes.draw do # They have periods in their URLs often: get 'site_texts' => 'site_texts#index' - get 'site_texts/:id.json' => 'site_texts#show', constraints: { id: /[\w.\-\+]+/i } - get 'site_texts/:id' => 'site_texts#show', constraints: { id: /[\w.\-\+]+/i } - put 'site_texts/:id.json' => 'site_texts#update', constraints: { id: /[\w.\-\+]+/i } - put 'site_texts/:id' => 'site_texts#update', constraints: { id: /[\w.\-\+]+/i } - delete 'site_texts/:id.json' => 'site_texts#revert', constraints: { id: /[\w.\-\+]+/i } - delete 'site_texts/:id' => 'site_texts#revert', constraints: { id: /[\w.\-\+]+/i } + get 'site_texts/:id.json' => 'site_texts#show', constraints: { id: /[\w.\-\+\%\&]+/i } + get 'site_texts/:id' => 'site_texts#show', constraints: { id: /[\w.\-\+\%\&]+/i } + put 'site_texts/:id.json' => 'site_texts#update', constraints: { id: /[\w.\-\+\%\&]+/i } + put 'site_texts/:id' => 'site_texts#update', constraints: { id: /[\w.\-\+\%\&]+/i } + delete 'site_texts/:id.json' => 'site_texts#revert', constraints: { id: /[\w.\-\+\%\&]+/i } + delete 'site_texts/:id' => 'site_texts#revert', constraints: { id: /[\w.\-\+\%\&]+/i } get 'reseed' => 'site_texts#get_reseed_options' post 'reseed' => 'site_texts#reseed' diff --git a/spec/requests/admin/site_texts_controller_spec.rb b/spec/requests/admin/site_texts_controller_spec.rb index 89132b9a708..a2edd37f045 100644 --- a/spec/requests/admin/site_texts_controller_spec.rb +++ b/spec/requests/admin/site_texts_controller_spec.rb @@ -172,6 +172,18 @@ RSpec.describe Admin::SiteTextsController do expect(site_text['value']).to eq(I18n.t("js.topic.list")) end + it 'returns a site text for a key with ampersand' do + get "/admin/customize/site_texts/js.emoji_picker.food_&_drink.json" + expect(response.status).to eq(200) + + json = ::JSON.parse(response.body) + + site_text = json['site_text'] + + expect(site_text['id']).to eq('js.emoji_picker.food_&_drink') + expect(site_text['value']).to eq(I18n.t("js.emoji_picker.food_&_drink")) + end + it 'returns not found for missing keys' do get "/admin/customize/site_texts/made_up_no_key_exists.json" expect(response.status).to eq(404) @@ -263,8 +275,8 @@ RSpec.describe Admin::SiteTextsController do expect(json['error_type']).to eq('not_found') end - it "works as expectd with correct keys" do - put '/admin/customize/site_texts/login_required.welcome_message.json', params: { + it "works as expected with correct keys" do + put '/admin/customize/site_texts/js.emoji_picker.animals_%26_nature.json', params: { site_text: { value: 'foo' } } @@ -273,7 +285,7 @@ RSpec.describe Admin::SiteTextsController do json = ::JSON.parse(response.body) site_text = json['site_text'] - expect(site_text['id']).to eq('login_required.welcome_message') + expect(site_text['id']).to eq('js.emoji_picker.animals_&_nature') expect(site_text['value']).to eq('foo') end