Skip to content

Commit 3be4461

Browse files
author
karthik
authored
Merge pull request #1460 from blackducksoftware/OTWO-5855
OTWO-5855: fix encoding issue on links index page
2 parents 24b1772 + 088ab47 commit 3be4461

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

app/helpers/links_helper.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# frozen_string_literal: true
22

3+
# rubocop: disable Lint/UriEscapeUnescape
4+
35
module LinksHelper
46
def safe_slice_host(url, length = 33)
5-
safe_url = sanitize(url)
7+
safe_url = sanitize(URI.encode(url))
68
hostname = URI.parse(safe_url).host
79
truncate(hostname, length: length)
810
end
911
end
12+
# rubocop: enable Lint/UriEscapeUnescape

test/helpers/links_helper_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require 'test_helper'
4+
5+
class LinksHelperTest < ActionView::TestCase
6+
include LinksHelper
7+
8+
it 'should slice host' do
9+
safe_slice_host('http://test.com/value').must_equal 'test.com'
10+
end
11+
12+
it 'should return host if url contains utf-8 encoding' do
13+
safe_slice_host('http://en.wikipedia.org/wiki/Étoilé').must_equal 'en.wikipedia.org'
14+
end
15+
16+
it 'should return utf-8 encoded host' do
17+
safe_slice_host('http://Étoilé.com/test').must_equal '%C3%89toil%C3%A9.com'
18+
end
19+
end

0 commit comments

Comments
 (0)