mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 17:45:26 +00:00
* fix automerge url parameters * fix url encoding & refactor raw request * handle trailing slash edgecases * minor code refactoring
37 lines
863 B
Go
37 lines
863 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"path"
|
|
"strings"
|
|
)
|
|
|
|
// Joins two relative paths and handles trailing slash edgecase
|
|
func JoinURLPath(elem1 string, elem2 string) string {
|
|
/*
|
|
Trailing Slash EdgeCase
|
|
Path.Join converts /test/ to /test
|
|
this should be handled manually
|
|
*/
|
|
if elem2 == "" {
|
|
return elem1
|
|
}
|
|
if elem2 == "/" || elem2 == "/?" {
|
|
// check for extra slash
|
|
if strings.HasSuffix(elem1, "/") && strings.HasPrefix(elem2, "/") {
|
|
elem1 = strings.TrimRight(elem1, "/")
|
|
}
|
|
// merge and return
|
|
return fmt.Sprintf("%v%v", elem1, elem2)
|
|
} else {
|
|
if strings.HasPrefix(elem2, "?") {
|
|
// path2 is parameter and not a url append and return
|
|
return fmt.Sprintf("%v%v", elem1, elem2)
|
|
}
|
|
// Note:
|
|
// path.Join implicitly calls path.Clean so any relative paths are filtered
|
|
// if not encoded properly
|
|
return path.Join(elem1, elem2)
|
|
}
|
|
}
|