Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add homepage url to user profile #5240

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
626e53f
successfully adds homepage url
jacklynhma Nov 14, 2024
9454dc2
adds test
jacklynhma Nov 14, 2024
1f66d68
fix homepage styling url
jacklynhma Nov 14, 2024
8267593
adds profile to show page
jacklynhma Nov 14, 2024
1ee00e3
fixes validation of url
jacklynhma Nov 14, 2024
2854947
passing test
jacklynhma Nov 14, 2024
708956b
tests are failing
jacklynhma Nov 14, 2024
eb0b5b4
undo change
jacklynhma Nov 14, 2024
d5ad960
passing tests
jacklynhma Nov 15, 2024
d3e13e9
add no follow
jacklynhma Nov 15, 2024
d02cad8
fix styling of link
jacklynhma Nov 15, 2024
14ff9bf
update user test
jacklynhma Nov 15, 2024
691a236
udpatetest
jacklynhma Nov 15, 2024
2f815db
Add rel=nofollow
martinemde Nov 20, 2024
3de3c7f
fix rel=nofollow on public profile
martinemde Nov 20, 2024
89cc35c
new XXS tests for homepage url
jacklynhma Nov 24, 2024
ff0086b
extract httpURL validator into a lib file and update the tests
jacklynhma Nov 24, 2024
dd31f9a
remove duplication
jacklynhma Nov 24, 2024
3e3fb7b
remove unneeded tests
jacklynhma Nov 24, 2024
b051551
add rescue
jacklynhma Nov 24, 2024
70feba9
Fix indentation
jacklynhma Dec 3, 2024
64d4a77
truncate really long homepage urls
jacklynhma Dec 3, 2024
f970fa0
renames test file so it doesn't conflict locally and adds confirmatio…
jacklynhma Dec 3, 2024
0c51ea0
restore file change
jacklynhma Dec 14, 2024
7033aff
fix indentation
jacklynhma Dec 14, 2024
df80ec6
add html_escape and rename files to allow tests to run locally
jacklynhma Dec 14, 2024
77b32e0
add html_escape for dashboards
jacklynhma Dec 14, 2024
41e72a5
fix failing tests
jacklynhma Dec 14, 2024
35b799d
change confirmation dialog prior to redirecting user
jacklynhma Dec 14, 2024
050b0a8
fix rubocop linter error
jacklynhma Dec 14, 2024
b63d9b5
create url append method
jacklynhma Dec 15, 2024
643462f
add tests for url helper method
jacklynhma Dec 15, 2024
d4042fd
fix rubocop
jacklynhma Dec 15, 2024
6ce413e
rename method
jacklynhma Dec 15, 2024
e3316bb
fix syntax error
jacklynhma Dec 15, 2024
0def58e
rename url helper and enhance url to escape html
jacklynhma Dec 15, 2024
6e3f245
fix syntax
jacklynhma Dec 15, 2024
7f3d0d3
remove test update since it is covered in a different PR
jacklynhma Dec 28, 2024
43e2dc2
add back profile_test.rb
jacklynhma Dec 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename url helper and enhance url to escape html
jacklynhma committed Dec 26, 2024
commit 0def58ef454091d271b32c6e8b6196387c501df7
6 changes: 3 additions & 3 deletions app/helpers/url_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module UrlHelper
def prepend_https(url)
def display_safe_url(url)
return "" if url.blank?
return url if url.start_with?("https://")
"https://#{url}"
return h(url) if url.start_with?("https://") || url.start_with?("http://")
return "https://#{h(url)}"
end
end
6 changes: 3 additions & 3 deletions app/views/dashboards/_subject.html.erb
Original file line number Diff line number Diff line change
@@ -26,10 +26,10 @@
<%= icon_tag("link", color: :primary, class: "w-6 text-orange mr-3") %>
<p class="text-neutral-800 dark:text-white"><%=
link_to(
truncate(prepend_https(user.homepage_url), length: 20),
h(prepend_https(user.homepage_url)),
truncate(display_safe_url(user.homepage_url), length: 20),
display_safe_url(user.homepage_url),
rel: "nofollow",
data: { confirm: "You are about to be redirected #{h(prepend_https(user.homepage_url))}" }
data: { confirm: "You are about to be redirected #{display_safe_url(user.homepage_url)}" }
)
%></p>
</div>
6 changes: 3 additions & 3 deletions app/views/profiles/show.html.erb
Original file line number Diff line number Diff line change
@@ -98,11 +98,11 @@
<p id="homepage-url">
<%=
link_to(
truncate(h(prepend_https(@user.homepage_url)),length: 20),
h(prepend_https(@user.homepage_url)),
truncate(display_safe_url(@user.homepage_url),length: 20),
display_safe_url(@user.homepage_url),
rel: "nofollow",
class: "profile__header__attribute t-link--black",
data: { confirm: "You are about to be redirected #{h(prepend_https(@user.homepage_url))} " }
data: { confirm: "You are about to be redirected #{display_safe_url(@user.homepage_url)} " }
)
%>
</p>
23 changes: 18 additions & 5 deletions test/unit/helpers/url_helper_test.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
require "test_helper"

class UrlHelperTest < ActionView::TestCase
context "prepend_https" do
include ERB::Util
context "display_safe_url" do
should "return url if it begins with https" do
assert_equal "https://www.awesomesite.com", prepend_https("https://www.awesomesite.com")
assert_equal "https://www.awesomesite.com", display_safe_url("https://www.awesomesite.com")
end
should "return empty string if url is empty" do
assert_equal "", prepend_https("")
assert_equal "", display_safe_url("")
end

should "display a url starting with http" do
assert_equal "http://www.awesomesite.com", display_safe_url("http://www.awesomesite.com")
end

should "return link with https if it does not begin with https" do
assert_equal "https://javascript:alert('hello');", prepend_https("javascript:alert('hello');")
assert_equal "https://javascript:alert(&#39;hello&#39;);", display_safe_url("javascript:alert('hello');")
end

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

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

should "return empty string if url is nil" do
assert_equal "", prepend_https(nil)
assert_equal "", display_safe_url(nil)
end
end
end