realURLPath replaces path root of p by r if r != "" and returns p otherwise. realURLPath assumes URL paths and assumes that both paths are cleaned.
(rURL *url.URL, p string)
| 41 | // realURLPath replaces path root of p by r if r != "" and returns p otherwise. |
| 42 | // realURLPath assumes URL paths and assumes that both paths are cleaned. |
| 43 | func realURLPath(rURL *url.URL, p string) (string, error) { |
| 44 | pURL, err := url.Parse(p) |
| 45 | if err != nil { |
| 46 | return "", err |
| 47 | } |
| 48 | if rURL == nil { |
| 49 | if !pURL.IsAbs() { |
| 50 | return "", errSchemeNotSpecified.New() |
| 51 | } |
| 52 | return p, nil |
| 53 | } |
| 54 | if pURL.IsAbs() { |
| 55 | return "", errSchemeSpecified.New() |
| 56 | } |
| 57 | if !rURL.IsAbs() { |
| 58 | return "", errSchemeNotSpecified.New() |
| 59 | } |
| 60 | return fmt.Sprintf("%s/%s", rURL, pURL.EscapedPath()), nil |
| 61 | } |
| 62 | |
| 63 | // realOSPath replaces path root of p by r if r != "" and returns p otherwise. |
| 64 | // realOSPath assumes operating system paths and that both paths are cleaned. |