From a0e78a5caf6bd337851073fc03847e4839be8a40 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sat, 1 Feb 2025 21:15:37 +0300 Subject: [PATCH] Use URI.encode_uri_component when generating share urls --- app/helpers/social_share_button_helper.rb | 4 ++-- test/helpers/social_share_button_helper_test.rb | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/helpers/social_share_button_helper.rb b/app/helpers/social_share_button_helper.rb index da49347c3..13a9f9e9e 100644 --- a/app/helpers/social_share_button_helper.rb +++ b/app/helpers/social_share_button_helper.rb @@ -35,8 +35,8 @@ module SocialShareButtonHelper def generate_share_url(site, title, url) site = site.to_sym - title = URI.encode_www_form_component(title) - url = URI.encode_www_form_component(url) + title = URI.encode_uri_component(title) + url = URI.encode_uri_component(url) case site when :email diff --git a/test/helpers/social_share_button_helper_test.rb b/test/helpers/social_share_button_helper_test.rb index 136298381..0634632b8 100644 --- a/test/helpers/social_share_button_helper_test.rb +++ b/test/helpers/social_share_button_helper_test.rb @@ -9,9 +9,14 @@ class SocialShareButtonHelperTest < ActionView::TestCase SOCIAL_SHARE_CONFIG.each_value do |icon| assert_dom buttons_dom, "div:has(a img[src='/images/#{icon}'])", :count => 1 do - assert_dom "a[href*='Test+Title']" + assert_dom "a[href*='Test%20Title']" assert_dom "a[href*='https%3A%2F%2Fexample.com']" end end end + + def test_generate_share_url_email + url = generate_share_url(:email, "Diary Entry Title", "https://osm.example.com/some/diary/entry") + assert_equal "mailto:?subject=Diary%20Entry%20Title&body=https%3A%2F%2Fosm.example.com%2Fsome%2Fdiary%2Fentry", url + end end -- 2.39.5