Encode each query param seperately using Addressable
Dieser Commit ist enthalten in:
Ursprung
1962388501
Commit
909f82095f
3 geänderte Dateien mit 64 neuen und 16 gelöschten Zeilen
|
@ -269,8 +269,8 @@ class CustomWizard::Action
|
||||||
params = basic_topic_params
|
params = basic_topic_params
|
||||||
|
|
||||||
if params[:title].present? && params[:raw].present?
|
if params[:title].present? && params[:raw].present?
|
||||||
url = "/new-topic?title=#{params[:title]}"
|
url = "/new-topic?title=#{encode_query_param(params[:title])}"
|
||||||
url += "&body=#{params[:raw]}"
|
url += "&body=#{encode_query_param(params[:raw])}"
|
||||||
|
|
||||||
if category_id = action_category
|
if category_id = action_category
|
||||||
if category = Category.find_by(id: category_id)
|
if category = Category.find_by(id: category_id)
|
||||||
|
@ -282,10 +282,10 @@ class CustomWizard::Action
|
||||||
url += "&tags=#{tags.join(',')}"
|
url += "&tags=#{tags.join(',')}"
|
||||||
end
|
end
|
||||||
|
|
||||||
route_to = Discourse.base_uri + UrlHelper.encode(url)
|
route_to = Discourse.base_uri + url
|
||||||
data['route_to'] = route_to
|
@result.output = data['route_to'] = route_to
|
||||||
|
|
||||||
log_info("route: #{route_to}")
|
log_success("route: #{route_to}")
|
||||||
else
|
else
|
||||||
log_error("invalid composer params", "title: #{params[:title]}; post: #{params[:raw]}")
|
log_error("invalid composer params", "title: #{params[:title]}; post: #{params[:raw]}")
|
||||||
end
|
end
|
||||||
|
@ -691,6 +691,10 @@ class CustomWizard::Action
|
||||||
user.user_avatar.save!
|
user.user_avatar.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def encode_query_param(param)
|
||||||
|
Addressable::URI.encode_component(param, Addressable::URI::CharacterClasses::UNRESERVED)
|
||||||
|
end
|
||||||
|
|
||||||
def log_success(message, detail = nil)
|
def log_success(message, detail = nil)
|
||||||
@log.push("success: #{message} - #{detail}")
|
@log.push("success: #{message} - #{detail}")
|
||||||
@result.success = true
|
@result.success = true
|
||||||
|
|
|
@ -5,6 +5,12 @@ describe CustomWizard::Action do
|
||||||
fab!(:category) { Fabricate(:category, name: 'cat1', slug: 'cat-slug') }
|
fab!(:category) { Fabricate(:category, name: 'cat1', slug: 'cat-slug') }
|
||||||
fab!(:group) { Fabricate(:group) }
|
fab!(:group) { Fabricate(:group) }
|
||||||
|
|
||||||
|
let(:open_composer) {
|
||||||
|
JSON.parse(File.open(
|
||||||
|
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/actions/open_composer.json"
|
||||||
|
).read)
|
||||||
|
}
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Group.refresh_automatic_group!(:trust_level_2)
|
Group.refresh_automatic_group!(:trust_level_2)
|
||||||
CustomWizard::Template.save(
|
CustomWizard::Template.save(
|
||||||
|
@ -99,18 +105,42 @@ describe CustomWizard::Action do
|
||||||
expect(user.profile_background_upload.id).to eq(upload.id)
|
expect(user.profile_background_upload.id).to eq(upload.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'opens a composer' do
|
context "open composer" do
|
||||||
wizard = CustomWizard::Builder.new(@template[:id], user).build
|
it 'works' do
|
||||||
wizard.create_updater(wizard.steps[0].id, step_1_field_1: "Text input").update
|
wizard = CustomWizard::Builder.new(@template[:id], user).build
|
||||||
|
wizard.create_updater(wizard.steps[0].id, step_1_field_1: "Text input").update
|
||||||
|
|
||||||
|
updater = wizard.create_updater(wizard.steps[1].id, {})
|
||||||
|
updater.update
|
||||||
|
|
||||||
|
category = Category.find_by(id: wizard.current_submission['action_8'])
|
||||||
|
|
||||||
|
expect(updater.result[:redirect_on_next]).to eq(
|
||||||
|
"/new-topic?title=Title%20of%20the%20composer%20topic&body=I%20am%20interpolating%20some%20user%20fields%20Angus%20angus%20angus%40email.com&category=#{category.slug}/#{category.id}&tags=tag1"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
updater = wizard.create_updater(wizard.steps[1].id, {})
|
it 'encodes special characters in the title and body' do
|
||||||
updater.update
|
open_composer['title'][0]['output'] = "Title that's special $"
|
||||||
|
open_composer['post_template'] = "Body & more body & more body"
|
||||||
category = Category.find_by(id: wizard.current_submission['action_8'])
|
|
||||||
|
wizard = CustomWizard::Wizard.new(@template, user)
|
||||||
expect(updater.result[:redirect_on_next]).to eq(
|
|
||||||
"/new-topic?title=Title%20of%20the%20composer%20topic&body=I%20am%20interpolating%20some%20user%20fields%20Angus%20angus%20angus@email.com&category=#{category.slug}/#{category.id}&tags=tag1"
|
action = CustomWizard::Action.new(
|
||||||
)
|
wizard: wizard,
|
||||||
|
action: open_composer,
|
||||||
|
user: user,
|
||||||
|
data: {}
|
||||||
|
)
|
||||||
|
action.perform
|
||||||
|
|
||||||
|
expect(action.result.success?).to eq(true)
|
||||||
|
|
||||||
|
decoded_output = CGI.parse(URI.parse(action.result.output).query)
|
||||||
|
|
||||||
|
expect(decoded_output['title'][0]).to eq("Title that's special $")
|
||||||
|
expect(decoded_output['body'][0]).to eq("Body & more body & more body")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates a category' do
|
it 'creates a category' do
|
||||||
|
|
14
spec/fixtures/actions/open_composer.json
gevendort
Normale Datei
14
spec/fixtures/actions/open_composer.json
gevendort
Normale Datei
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"id": "open_composer_action",
|
||||||
|
"type": "open_composer",
|
||||||
|
"title": [
|
||||||
|
{
|
||||||
|
"type": "assignment",
|
||||||
|
"output": "Title content",
|
||||||
|
"output_type": "text",
|
||||||
|
"output_connector": "set"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"post_builder": true,
|
||||||
|
"post_template": "Post content"
|
||||||
|
}
|
Laden …
In neuem Issue referenzieren