Skip to content

Commit

Permalink
Merge pull request #1460 from blackducksoftware/OTWO-5855
Browse files Browse the repository at this point in the history
OTWO-5855: fix encoding issue on links index page
  • Loading branch information
karthik committed Feb 22, 2020
2 parents 24b1772 + 088ab47 commit 3be4461
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/helpers/links_helper.rb
@@ -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
19 changes: 19 additions & 0 deletions test/helpers/links_helper_test.rb
@@ -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

0 comments on commit 3be4461

Please sign in to comment.