do not treat generic bytes as strings into errors

This commit is contained in:
aler9
2022-01-23 12:39:21 +01:00
parent f6a86b8789
commit 8ef623f56d
4 changed files with 9 additions and 9 deletions

View File

@@ -75,10 +75,10 @@ func (req *Request) Read(rb *bufio.Reader) error {
if err != nil { if err != nil {
return err return err
} }
proto := string(byts[:len(byts)-1]) proto := byts[:len(byts)-1]
if proto != rtspProtocol10 { if string(proto) != rtspProtocol10 {
return fmt.Errorf("expected '%s', got '%s'", rtspProtocol10, proto) return fmt.Errorf("expected '%s', got %v", rtspProtocol10, proto)
} }
err = readByteEqual(rb, '\n') err = readByteEqual(rb, '\n')

View File

@@ -187,7 +187,7 @@ func TestRequestReadErrors(t *testing.T) {
{ {
"empty protocol", "empty protocol",
[]byte("GET rtsp://testing123 \r\n"), []byte("GET rtsp://testing123 \r\n"),
"expected 'RTSP/1.0', got ''", "expected 'RTSP/1.0', got []",
}, },
{ {
"invalid URL", "invalid URL",
@@ -197,7 +197,7 @@ func TestRequestReadErrors(t *testing.T) {
{ {
"invalid protocol", "invalid protocol",
[]byte("GET rtsp://testing123 RTSP/2.0\r\n"), []byte("GET rtsp://testing123 RTSP/2.0\r\n"),
"expected 'RTSP/1.0', got 'RTSP/2.0'", "expected 'RTSP/1.0', got [82 84 83 80 47 50 46 48]",
}, },
{ {
"invalid header", "invalid header",

View File

@@ -139,10 +139,10 @@ func (res *Response) Read(rb *bufio.Reader) error {
if err != nil { if err != nil {
return err return err
} }
proto := string(byts[:len(byts)-1]) proto := byts[:len(byts)-1]
if proto != rtspProtocol10 { if string(proto) != rtspProtocol10 {
return fmt.Errorf("expected '%s', got '%s'", rtspProtocol10, proto) return fmt.Errorf("expected '%s', got %v", rtspProtocol10, proto)
} }
byts, err = readBytesLimited(rb, ' ', 4) byts, err = readBytesLimited(rb, ' ', 4)

View File

@@ -139,7 +139,7 @@ func TestResponseReadErrors(t *testing.T) {
{ {
"invalid protocol", "invalid protocol",
[]byte("RTSP/2.0 200 OK\r\n"), []byte("RTSP/2.0 200 OK\r\n"),
"expected 'RTSP/1.0', got 'RTSP/2.0'", "expected 'RTSP/1.0', got [82 84 83 80 47 50 46 48]",
}, },
{ {
"code too long", "code too long",