diff --git a/app/helpers/url_helper.rb b/app/helpers/url_helper.rb index b6999d83539..64d79fec3d8 100644 --- a/app/helpers/url_helper.rb +++ b/app/helpers/url_helper.rb @@ -1,5 +1,5 @@ module UrlHelper - def append_https(url) + def prepend_https(url) return "" if url.blank? return url if url.start_with?("https://") "https://#{url}" diff --git a/app/views/dashboards/_subject.html.erb b/app/views/dashboards/_subject.html.erb index 1f32e6a6dcd..f03485bfd47 100644 --- a/app/views/dashboards/_subject.html.erb +++ b/app/views/dashboards/_subject.html.erb @@ -26,10 +26,10 @@ <%= icon_tag("link", color: :primary, class: "w-6 text-orange mr-3") %>
<%= link_to( - truncate(append_https(user.homepage_url), length: 20), - h(append_https(user.homepage_url)), + truncate(prepend_https(user.homepage_url), length: 20), + h(prepend_https(user.homepage_url)), rel: "nofollow", - data: { confirm: "You are about to be redirected #{h(append_https(user.homepage_url))}" } + data: { confirm: "You are about to be redirected #{h(prepend_https(user.homepage_url))}" } ) %>
diff --git a/app/views/profiles/show.html.erb b/app/views/profiles/show.html.erb index e4a16b9f70f..651d883774a 100644 --- a/app/views/profiles/show.html.erb +++ b/app/views/profiles/show.html.erb @@ -98,11 +98,11 @@<%= link_to( - truncate(h(append_https(@user.homepage_url)),length: 20), - h(append_https(@user.homepage_url)), + truncate(h(prepend_https(@user.homepage_url)),length: 20), + h(prepend_https(@user.homepage_url)), rel: "nofollow", class: "profile__header__attribute t-link--black", - data: { confirm: "You are about to be redirected #{{h(append_https(user.homepage_url))}}" } + data: { confirm: "You are about to be redirected #{{h(prepend_https(user.homepage_url))}}" } ) %>
diff --git a/test/unit/helpers/url_helper_test.rb b/test/unit/helpers/url_helper_test.rb index f69add86213..0b0c64989f1 100644 --- a/test/unit/helpers/url_helper_test.rb +++ b/test/unit/helpers/url_helper_test.rb @@ -1,20 +1,20 @@ require "test_helper" class UrlHelperTest < ActionView::TestCase - context "append_https" do + context "prepend_https" do should "return url if it begins with https" do - assert_equal "https://www.awesomesite.com", append_https("https://www.awesomesite.com") + assert_equal "https://www.awesomesite.com", prepend_https("https://www.awesomesite.com") end should "return empty string if url is empty" do - assert_equal "", append_https("") + assert_equal "", prepend_https("") end should "return link with https if it does not begin with https" do - assert_equal "https://javascript:alert('hello');", append_https("javascript:alert('hello');") + assert_equal "https://javascript:alert('hello');", prepend_https("javascript:alert('hello');") end should "return empty string if url is nil" do - assert_equal "", append_https(nil) + assert_equal "", prepend_https(nil) end end end