Properly decode URLs
This commit is contained in:
@@ -99,16 +99,21 @@ func NormalizeLink(linkLine string, currentURL string) (link string, descr strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
originalURLStr := matches[1]
|
originalURLStr := matches[1]
|
||||||
|
decodedURLStr, err := url.QueryUnescape(originalURLStr)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", fmt.Errorf("Error decoding URL: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
restOfLine := ""
|
restOfLine := ""
|
||||||
if len(matches) > 2 {
|
if len(matches) > 2 {
|
||||||
restOfLine = matches[2]
|
restOfLine = matches[2]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the URL from the link line
|
// Parse the URL from the link line
|
||||||
parsedURL, err := url.Parse(originalURLStr)
|
parsedURL, err := url.Parse(decodedURLStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If URL parsing fails, return an error
|
// 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
|
// Resolve relative URLs against the base URL
|
||||||
|
|||||||
4
main.go
4
main.go
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
@@ -11,7 +12,10 @@ import (
|
|||||||
|
|
||||||
var CONFIG Config
|
var CONFIG Config
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
wg.Add(1)
|
||||||
CONFIG = *getConfig()
|
CONFIG = *getConfig()
|
||||||
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
||||||
zerolog.SetGlobalLevel(CONFIG.logLevel)
|
zerolog.SetGlobalLevel(CONFIG.logLevel)
|
||||||
|
|||||||
Reference in New Issue
Block a user