Commit 1082e32a authored by Pavel Shutsin's avatar Pavel Shutsin

Merge branch '351685-a-utility-to-append-param-to-query-string-uri' into 'master'

Resolve "A utility to append param to query string  URI"

See merge request gitlab-org/gitlab!79758
parents e6a15ed7 e4266d5c
...@@ -35,10 +35,8 @@ class TrialRegistrationsController < RegistrationsController ...@@ -35,10 +35,8 @@ class TrialRegistrationsController < RegistrationsController
stored_url = stored_location_for(:user) stored_url = stored_location_for(:user)
return unless stored_url.present? return unless stored_url.present?
redirect_uri = URI.parse(stored_url) redirect_uri = Gitlab::Utils.add_url_parameters(stored_url, onboarding: true)
new_query = URI.decode_www_form(String(redirect_uri.query)) << ['onboarding', true] store_location_for(:user, redirect_uri)
redirect_uri.query = URI.encode_www_form(new_query)
store_location_for(:user, redirect_uri.to_s)
end end
def sign_up_params def sign_up_params
......
...@@ -203,6 +203,13 @@ module Gitlab ...@@ -203,6 +203,13 @@ module Gitlab
rescue Addressable::URI::InvalidURIError, TypeError rescue Addressable::URI::InvalidURIError, TypeError
end end
def add_url_parameters(url, params)
uri = parse_url(url.to_s)
uri.query_values = uri.query_values.to_h.merge(params.to_h.stringify_keys)
uri.query_values = nil if uri.query_values.empty?
uri.to_s
end
def removes_sensitive_data_from_url(uri_string) def removes_sensitive_data_from_url(uri_string)
uri = parse_url(uri_string) uri = parse_url(uri_string)
......
...@@ -439,6 +439,23 @@ RSpec.describe Gitlab::Utils do ...@@ -439,6 +439,23 @@ RSpec.describe Gitlab::Utils do
end end
end end
describe '.add_url_parameters' do
subject { described_class.add_url_parameters(url, params) }
where(:url, :params, :expected_url) do
nil | nil | ''
nil | { b: 3, a: 2 } | '?a=2&b=3'
'https://gitlab.com' | nil | 'https://gitlab.com'
'https://gitlab.com' | { b: 3, a: 2 } | 'https://gitlab.com?a=2&b=3'
'https://gitlab.com?a=1#foo' | { b: 3, 'a': 2 } | 'https://gitlab.com?a=2&b=3#foo'
'https://gitlab.com?a=1#foo' | [[:b, 3], [:a, 2]] | 'https://gitlab.com?a=2&b=3#foo'
end
with_them do
it { is_expected.to eq(expected_url) }
end
end
describe '.removes_sensitive_data_from_url' do describe '.removes_sensitive_data_from_url' do
it 'returns string object' do it 'returns string object' do
expect(described_class.removes_sensitive_data_from_url('http://gitlab.com')).to be_instance_of(String) expect(described_class.removes_sensitive_data_from_url('http://gitlab.com')).to be_instance_of(String)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment