File tree 2 files changed +23
-1
lines changed 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
+ # rubocop: disable Lint/UriEscapeUnescape
4
+
3
5
module LinksHelper
4
6
def safe_slice_host ( url , length = 33 )
5
- safe_url = sanitize ( url )
7
+ safe_url = sanitize ( URI . encode ( url ) )
6
8
hostname = URI . parse ( safe_url ) . host
7
9
truncate ( hostname , length : length )
8
10
end
9
11
end
12
+ # rubocop: enable Lint/UriEscapeUnescape
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments