mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 19:08:58 +00:00
Merge pull request #1212 from cqcallaw/upnp
Properly handle absolute URLs when parsing UPnP service control URLs
This commit is contained in:
commit
2a58ca7697
@ -448,19 +448,27 @@ func getIGDServices(rootURL string, device upnpDevice, wanDeviceURN string, wanC
|
|||||||
}
|
}
|
||||||
|
|
||||||
func replaceRawPath(u *url.URL, rp string) {
|
func replaceRawPath(u *url.URL, rp string) {
|
||||||
var p, q string
|
asURL, err := url.Parse(rp)
|
||||||
fs := strings.Split(rp, "?")
|
if err != nil {
|
||||||
p = fs[0]
|
return
|
||||||
if len(fs) > 1 {
|
} else if asURL.IsAbs() {
|
||||||
q = fs[1]
|
u.Path = asURL.Path
|
||||||
}
|
u.RawQuery = asURL.RawQuery
|
||||||
|
|
||||||
if p[0] == '/' {
|
|
||||||
u.Path = p
|
|
||||||
} else {
|
} else {
|
||||||
u.Path += p
|
var p, q string
|
||||||
|
fs := strings.Split(rp, "?")
|
||||||
|
p = fs[0]
|
||||||
|
if len(fs) > 1 {
|
||||||
|
q = fs[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
if p[0] == '/' {
|
||||||
|
u.Path = p
|
||||||
|
} else {
|
||||||
|
u.Path += p
|
||||||
|
}
|
||||||
|
u.RawQuery = q
|
||||||
}
|
}
|
||||||
u.RawQuery = q
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func soapRequest(url, service, function, message string) ([]byte, error) {
|
func soapRequest(url, service, function, message string) ([]byte, error) {
|
||||||
|
@ -17,6 +17,7 @@ package upnp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,3 +41,25 @@ func TestExternalIPParsing(t *testing.T) {
|
|||||||
t.Error("Parse of SOAP request failed.")
|
t.Error("Parse of SOAP request failed.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestControlURLParsing(t *testing.T) {
|
||||||
|
rootURL := "http://192.168.243.1:80/igd.xml"
|
||||||
|
|
||||||
|
u, _ := url.Parse(rootURL)
|
||||||
|
subject := "/upnp?control=WANCommonIFC1"
|
||||||
|
expected := "http://192.168.243.1:80/upnp?control=WANCommonIFC1"
|
||||||
|
replaceRawPath(u, subject)
|
||||||
|
|
||||||
|
if u.String() != expected {
|
||||||
|
t.Error("URL normalization of", subject, "failed; expected", expected, "got", u.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
u, _ = url.Parse(rootURL)
|
||||||
|
subject = "http://192.168.243.1:80/upnp?control=WANCommonIFC1"
|
||||||
|
expected = "http://192.168.243.1:80/upnp?control=WANCommonIFC1"
|
||||||
|
replaceRawPath(u, subject)
|
||||||
|
|
||||||
|
if u.String() != expected {
|
||||||
|
t.Error("URL normalization of", subject, "failed; expected", expected, "got", u.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user