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 d355431
Showing 1 changed file with 17 additions and 4 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 @@ -221,11 +221,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

0 comments on commit d355431

Please sign in to comment.