Skip to content

Commit

Permalink
Handle all href for creating_index
Browse files Browse the repository at this point in the history
  • Loading branch information
kyuden committed Dec 25, 2017
1 parent 2d108dc commit 19608b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/wovnrb/lang.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def switch_dom_lang(dom, store, values, url, headers)

def index_href_for_encoding_and_decoding(dom)
result = {}
dom.css('a').each do |a_tag|
dom.xpath('//*[@href]').each do |a_tag|
url = a_tag['href']
encoded_url = Addressable::URI.parse(url).normalize.to_s
result[encoded_url] = url if encoded_url != url
Expand Down
6 changes: 6 additions & 0 deletions test/lib/lang_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,10 @@ def test_switch_dom_lang_for_keeping_originl_encoding_decoding
lang = Lang.new('ja')
header = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://page.com'), Wovnrb.get_settings)
html = <<-HTML
<head>
<link rel="stylesheet" type="text/css" href="%3Ca%3E%E3%81%B5%E3%82%86%3C%2Fa%3E/theme.css">
<link rel="stylesheet" type="text/css" href="テスト.css">
</head>
<ul>
<li><a href="http://page.com/%e5%ba%83%e5%b0%be">encoded japanese path</a></li>
<li><a href="http://page.com/テスト/DxA9J">no encoded japanese path</a></li>
Expand All @@ -600,6 +604,8 @@ def test_switch_dom_lang_for_keeping_originl_encoding_decoding
url = header.url

swapped_body = lang.switch_dom_lang(dom, Store.instance, generate_values, url, header)
assert(swapped_body.include?('<link rel="stylesheet" type="text/css" href="%3Ca%3E%E3%81%B5%E3%82%86%3C%2Fa%3E/theme.css">'))
assert(swapped_body.include?('<link rel="stylesheet" type="text/css" href="テスト.css">'))
assert(swapped_body.include?('<a href="http://page.com/ja/%e5%ba%83%e5%b0%be">encoded japanese path</a>'))
assert(swapped_body.include?('<a href="http://page.com/ja/テスト/DxA9J">no encoded japanese path</a>'))
assert(swapped_body.include?('<a href="http://page.com/ja/#DnE897">decoded invalid path</a>'))
Expand Down

0 comments on commit 19608b3

Please sign in to comment.