mirror of
https://github.com/aler9/gortsplib
synced 2025-10-21 06:09:33 +08:00
base: fix PathSplitQuery
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func stringsReverseIndex(s, substr string) int {
|
func stringsReverseIndex(s, substr string) int {
|
||||||
@@ -35,7 +36,7 @@ func PathSplitControlAttribute(pathAndQuery string) (int, string, bool) {
|
|||||||
|
|
||||||
// PathSplitQuery splits a path from a query.
|
// PathSplitQuery splits a path from a query.
|
||||||
func PathSplitQuery(pathAndQuery string) (string, string) {
|
func PathSplitQuery(pathAndQuery string) (string, string) {
|
||||||
i := stringsReverseIndex(pathAndQuery, "?")
|
i := strings.Index(pathAndQuery, "?")
|
||||||
if i >= 0 {
|
if i >= 0 {
|
||||||
return pathAndQuery[:i], pathAndQuery[i:]
|
return pathAndQuery[:i], pathAndQuery[i:]
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,10 @@ func TestURLRTSPPath(t *testing.T) {
|
|||||||
MustParseURL("rtsp://192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp"),
|
MustParseURL("rtsp://192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp"),
|
||||||
"user=tmp&password=BagRep1!&channel=1&stream=0.sdp",
|
"user=tmp&password=BagRep1!&channel=1&stream=0.sdp",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
MustParseURL("rtsp://localhost:8554/teststream?query1?query2"),
|
||||||
|
"teststream",
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
b, ok := ca.u.RTSPPath()
|
b, ok := ca.u.RTSPPath()
|
||||||
require.Equal(t, true, ok)
|
require.Equal(t, true, ok)
|
||||||
|
Reference in New Issue
Block a user