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 7c78c55
Show file tree
Hide file tree
Showing 10 changed files with 492 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/html_proofer/attribute/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,22 @@ 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})+$/
parsed_url = Addressable::URI.parse(@url)
url = if parsed_url.scheme.nil?
parsed_url
else
parsed_url.normalize
end.to_s

@url = Addressable::URI.parse(@url).normalize.to_s
# normalize strips this off, which causes issues with cache
@url = if @url.end_with?("/") && !url.end_with?("/")
"#{url}/"
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.

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

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

Large diffs are not rendered by default.

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

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

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

Loading

0 comments on commit 7c78c55

Please sign in to comment.