Properly decode URLs

This commit is contained in:
2024-10-10 18:39:27 +03:00
parent 8278f2b204
commit 212345764b
2 changed files with 11 additions and 2 deletions

View File

@@ -99,16 +99,21 @@ func NormalizeLink(linkLine string, currentURL string) (link string, descr strin
}
originalURLStr := matches[1]
decodedURLStr, err := url.QueryUnescape(originalURLStr)
if err != nil {
return "", "", fmt.Errorf("Error decoding URL: %w", err)
}
restOfLine := ""
if len(matches) > 2 {
restOfLine = matches[2]
}
// Parse the URL from the link line
parsedURL, err := url.Parse(originalURLStr)
parsedURL, err := url.Parse(decodedURLStr)
if err != nil {
// If URL parsing fails, return an error
return "", "", fmt.Errorf("Invalid URL in link line '%s': %v", originalURLStr, err)
return "", "", fmt.Errorf("Invalid URL in link line '%s': %v", decodedURLStr, err)
}
// Resolve relative URLs against the base URL

View File

@@ -3,6 +3,7 @@ package main
import (
"os"
"strings"
"sync"
"time"
"github.com/rs/zerolog"
@@ -11,7 +12,10 @@ import (
var CONFIG Config
var wg sync.WaitGroup
func main() {
wg.Add(1)
CONFIG = *getConfig()
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
zerolog.SetGlobalLevel(CONFIG.logLevel)