Fix link parsing

This commit is contained in:
Trevor Slocum 2020-11-23 21:35:33 -08:00
parent 26115183a9
commit 9cf58a9982
2 changed files with 22 additions and 13 deletions

View file

@ -68,20 +68,29 @@ func Convert(page []byte, u string) []byte {
continue
}
if l >= 7 && bytes.HasPrefix(line, []byte("=> ")) {
split := bytes.SplitN(line[3:], []byte(" "), 2)
if l >= 6 && bytes.HasPrefix(line, []byte("=>")) {
splitStart := 2
if line[splitStart+1] == ' ' || line[splitStart+1] == '\t' {
splitStart++
}
split := bytes.SplitN(line[splitStart:], []byte(" "), 2)
if len(split) != 2 {
split = bytes.SplitN(line[3:], []byte("\t"), 2)
split = bytes.SplitN(line[splitStart:], []byte("\t"), 2)
}
linkURL := line[splitStart:]
linkLabel := line[splitStart:]
if len(split) == 2 {
link := append([]byte(`<a href="`), rewriteURL(string(split[0]), parsedURL)...)
link = append(link, []byte(`">`)...)
link = append(link, split[1]...)
link = append(link, []byte(`</a>`)...)
result = append(result, link...)
result = append(result, []byte("<br>")...)
continue
linkURL = split[0]
linkLabel = split[1]
}
link := append([]byte(`<a href="`), rewriteURL(string(linkURL), parsedURL)...)
link = append(link, []byte(`">`)...)
link = append(link, linkLabel...)
link = append(link, []byte(`</a>`)...)
result = append(result, link...)
result = append(result, []byte("<br>")...)
continue
}
heading := 0

View file

@ -114,7 +114,7 @@ func fetch(u string) ([]byte, []byte, error) {
}
if !bytes.HasPrefix(header, []byte("2")) {
return header, []byte(fmt.Sprintf("Unexpected header: %s", header)), nil
return header, []byte(fmt.Sprintf(pageHeader+"Server sent unexpected header:<br><br><b>%s</b>", header) + pageFooter), nil
}
if bytes.HasPrefix(header, []byte("20 text/html")) {
@ -223,13 +223,13 @@ func LastRequestTime() int64 {
}
// SetClientCertificate sets the client certificate to use for a domain.
func SetClientCertificate(domain string, certificate string, privateKey string) error {
func SetClientCertificate(domain string, certificate []byte, privateKey []byte) error {
if len(certificate) == 0 || len(privateKey) == 0 {
delete(clientCerts, domain)
return nil
}
clientCert, err := tls.LoadX509KeyPair(certificate, privateKey)
clientCert, err := tls.X509KeyPair(certificate, privateKey)
if err != nil {
return ErrInvalidCertificate
}