gjtorikian / html-proofer

Test your rendered HTML files to make sure they're accurate.
MIT License
1.57k stars 199 forks source link

Hash checker expects # in `id` #844

Closed chrisclayson closed 3 months ago

chrisclayson commented 3 months ago

I've come across what, I think, is a bug in the hash checker.

You have this XPath:

xpath = [%(//*[@name="#{hash}"]|/*[@name="#{unencoded_hash}"]|//*[@id="#{hash}"]|//*[@id="#{unencoded_hash}"])]

In HTML terms the anchor in the document would be where the id or name is {hash} not #{hash} right? I'm sure some peeps do include the hash in the id, but I'm 99% certain the intention is that it wouldn't be there. Maybe this XPath should be something like (or something a little more optimised, my XPath isn't that strong):

xpath = [%(//*[@name="#{hash}"]|//*[@name="{hash}"]|//*[@name="#{unencoded_hash}"]|[@name="{unencoded_hash}"]|//*[@id="#{hash}"]|//*[@id="{hash}"]|//*[@id="#{unencoded_hash}"]|//*[@id="{unencoded_hash}"])]
chrisclayson commented 3 months ago

Oh ignore me ... just realised the # is a substitution in Ruby 🤦🏻