wjdp / htmltest

:white_check_mark: Test generated HTML for problems
MIT License
323 stars 54 forks source link

Panic when meta refresh URL is single-quoted #92

Closed kaushalmodi closed 6 years ago

kaushalmodi commented 6 years ago

Here's a simple test HTML file:

test.html

<!doctype html>
<html lang="en">
    <head>
        <title>ox-hugo Test Site</title>
        <meta http-equiv="refresh" content="0; URL='https://github.com/kaushalmodi/ox-hugo/issues'" />
    </head>
</html>

How to make htmltest panic

htmltest test.html

Log

panic: parse 'https://github.com/kaushalmodi/ox-hugo/issues': first path segment in URL cannot contain colon

goroutine 1 [running]:
github.com/wjdp/htmltest/output.CheckErrorPanic(0x78d580, 0xc0000a9dd0)
        /home/kmodi/go.apps/src/github.com/wjdp/htmltest/output/error.go:22 +0x86
github.com/wjdp/htmltest/htmldoc.NewReference(0xc0001c04d0, 0xc0001c08c0, 0xc00001cb87, 0x2f, 0xc00000dd20)
        /home/kmodi/go.apps/src/github.com/wjdp/htmltest/htmldoc/reference.go:34 +0x109
github.com/wjdp/htmltest/htmltest.(*HTMLTest).checkMetaRefresh(0xc0000ecb40, 0xc0001c04d0, 0xc0001c08c0)
        /home/kmodi/go.apps/src/github.com/wjdp/htmltest/htmltest/check-meta.go:31 +0x200
github.com/wjdp/htmltest/htmltest.(*HTMLTest).checkMeta(0xc0000ecb40, 0xc0001c04d0, 0xc0001c08c0)
        /home/kmodi/go.apps/src/github.com/wjdp/htmltest/htmltest/check-meta.go:12 +0x54
github.com/wjdp/htmltest/htmltest.(*HTMLTest).testDocument(0xc0000ecb40, 0xc0001c04d0)
        /home/kmodi/go.apps/src/github.com/wjdp/htmltest/htmltest/htmltest.go:218 +0x479
github.com/wjdp/htmltest/htmltest.Test(0xc0000a99e0, 0x1, 0x1, 0x49)
        /home/kmodi/go.apps/src/github.com/wjdp/htmltest/htmltest/htmltest.go:138 +0x91f
main.run(0xc0000a99e0, 0xc0000a99e0)
        /home/kmodi/go.apps/src/github.com/wjdp/htmltest/main.go:159 +0x1e8
main.main()
        /home/kmodi/go.apps/src/github.com/wjdp/htmltest/main.go:66 +0x298
wjdp commented 6 years ago

Thanks for the report

wjdp commented 6 years ago

Seems to be because of the single quotes around the url

wjdp commented 6 years ago

Have made this raise an error rather than crashing the whole program. Dug up the spec and meta urls should not start with a single or double quote.

kaushalmodi commented 6 years ago

Thanks, I probably picked that up from some bad example online.

The URL isn't starting with single quote.. I'm wrapping the whole URL in single quotes.. I thought that's needed based on whatever example I followed.

kaushalmodi commented 6 years ago

I'll try the same without any single quote wrapping. Note that the single quotes URL's in those meta redirects do work though.

kaushalmodi commented 6 years ago

It's this example: https://css-tricks.com/redirect-web-page/#article-header-id-1

kaushalmodi commented 6 years ago

I just fixed my meta redirects by removing the single quotes. Thanks.

wjdp commented 6 years ago

Yeah it's pretty common for something to be against the spec but work in most browsers. I was a little torn on this as it's rather pedantic but is the correct thing to do.