Skip to content

Commit

Permalink
Remove unnecessary regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed May 6, 2024
1 parent eecf75d commit 2244cab
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/html_proofer/attribute/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,28 @@ 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
normalized_url = parsed_url.normalize
if normalized_url.domain&.starts_with?("xn--")
normalized_url = normalized_url.display_uri
end
normalized_url
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

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

0 comments on commit 2244cab

Please sign in to comment.