-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1460 from blackducksoftware/OTWO-5855
OTWO-5855: fix encoding issue on links index page
- Loading branch information
Showing
2 changed files
with
23 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
# rubocop: disable Lint/UriEscapeUnescape | ||
|
||
module LinksHelper | ||
def safe_slice_host(url, length = 33) | ||
safe_url = sanitize(url) | ||
safe_url = sanitize(URI.encode(url)) | ||
hostname = URI.parse(safe_url).host | ||
truncate(hostname, length: length) | ||
end | ||
end | ||
# rubocop: enable Lint/UriEscapeUnescape |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class LinksHelperTest < ActionView::TestCase | ||
include LinksHelper | ||
|
||
it 'should slice host' do | ||
safe_slice_host('http://test.com/value').must_equal 'test.com' | ||
end | ||
|
||
it 'should return host if url contains utf-8 encoding' do | ||
safe_slice_host('http://en.wikipedia.org/wiki/Étoilé').must_equal 'en.wikipedia.org' | ||
end | ||
|
||
it 'should return utf-8 encoded host' do | ||
safe_slice_host('http://Étoilé.com/test').must_equal '%C3%89toil%C3%A9.com' | ||
end | ||
end |