Skip to content

Commit

Permalink
fix syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
jacklynhma committed Dec 26, 2024
1 parent 0def58e commit 6e3f245
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/helpers/url_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module UrlHelper
def display_safe_url(url)
return "" if url.blank?
return h(url) if url.start_with?("https://") || url.start_with?("http://")
return "https://#{h(url)}"
return h(url) if url.start_with?("https://", "http://")
"https://#{h(url)}"
end
end
8 changes: 4 additions & 4 deletions test/unit/helpers/url_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class UrlHelperTest < ActionView::TestCase
assert_equal "https://javascript:alert(&#39;hello&#39;);", display_safe_url("javascript:alert('hello');")
end

should "escape html" do
should "escape html" do
assert_equal "https://&lt;script&gt;alert(&#39;hello&#39;);&lt;/script&gt;https://www", display_safe_url("<script>alert('hello');</script>https://www")
end
end

should "prepend https if url does not begin with http or https" do
should "prepend https if url does not begin with http or https" do
assert_equal "https://www.awesomesite.com/https://javascript:alert(&#39;hello&#39;);", display_safe_url("www.awesomesite.com/https://javascript:alert('hello');")
end
end

should "return empty string if url is nil" do
assert_equal "", display_safe_url(nil)
Expand Down

0 comments on commit 6e3f245

Please sign in to comment.