Skip to content

Commit

Permalink
Merge pull request #820 from gjtorikian/regexpiry
Browse files Browse the repository at this point in the history
Remove unnecessary regexp
  • Loading branch information
gjtorikian committed May 7, 2024
1 parent 1c8b2c1 commit f9ca010
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
21 changes: 17 additions & 4 deletions lib/html_proofer/attribute/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,24 @@ def without_hash
@url.to_s.sub(/##{hash}/, "")
end

# catch any obvious issues, like strings in port numbers
# catch any obvious issues
private def clean_url!
return if @url =~ /^([!#{Regexp.last_match(0)}-;=?-\[\]_a-z~]|%[0-9a-fA-F]{2})+$/

@url = Addressable::URI.parse(@url).normalize.to_s
parsed_url = Addressable::URI.parse(@url)
url = if parsed_url.scheme.nil?
parsed_url
else
parsed_url.normalize
end.to_s

# normalize strips this off, which causes issues with cache
@url = if @url.end_with?("/") && !url.end_with?("/")
"#{url}/"
elsif !@url.end_with?("/") && url.end_with?("/")
url.chop
else
url
end
rescue Addressable::URI::InvalidURIError # rubocop:disable Lint/SuppressedException; error will be reported at check time
end

private def swap_urls!
Expand Down
2 changes: 1 addition & 1 deletion spec/html-proofer/fixtures/links/unicode_domain.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

<body>

<p><a href="https://αναπτυξηεφαρμογων.gr">A real link</a></p>
<p><a href="https://granö.fi">A real link</a></p>

</html>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f9ca010

Please sign in to comment.