Fix RTSP session header parsing regex error.

Issue: #9416

The dash "-" in the brackets must be escaped, or it acts like a range
operator.

PiperOrigin-RevId: 395909845
This commit is contained in:
claincly 2021-09-10 13:53:40 +01:00 committed by Christos Tsilopoulos
parent 5a5aeda3ec
commit 927d507397
3 changed files with 13 additions and 1 deletions

View file

@ -36,6 +36,8 @@
([#9379](https://github.com/google/ExoPlayer/issues/9379)).
* Handle partial URIs in RTP-Info headers
([#9346](https://github.com/google/ExoPlayer/issues/9346)).
* Fix RTSP Session header handling
([#9416](https://github.com/google/ExoPlayer/issues/9416)).
* UI:
* Use `defStyleAttr` when obtaining styled attributes in
`StyledPlayerView`, `PlayerView` and `PlayerControlView`

View file

@ -94,7 +94,7 @@ import java.util.regex.Pattern;
// Session header pattern, see RFC2326 Sections 3.4 and 12.37.
private static final Pattern SESSION_HEADER_PATTERN =
Pattern.compile("([\\w$-_.+]+)(?:;\\s?timeout=(\\d+))?");
Pattern.compile("([\\w$\\-_.+]+)(?:;\\s?timeout=(\\d+))?");
// WWW-Authenticate header pattern, see RFC2068 Sections 14.46 and RFC2069.
private static final Pattern WWW_AUTHENTICATION_HEADER_DIGEST_PATTERN =

View file

@ -359,6 +359,16 @@ public final class RtspMessageUtilTest {
assertThat(sessionHeader.sessionId).isEqualTo("610a63df-9b57.4856_97ac$665f+56e9c04");
}
@Test
public void parseSessionHeader_withSessionIdContainingSpecialCharactersAndTimeout_succeeds()
throws Exception {
String sessionHeaderString = "610a63df-9b57.4856_97ac$665f+56e9c04;timeout=60";
RtspMessageUtil.RtspSessionHeader sessionHeader =
RtspMessageUtil.parseSessionHeader(sessionHeaderString);
assertThat(sessionHeader.sessionId).isEqualTo("610a63df-9b57.4856_97ac$665f+56e9c04");
assertThat(sessionHeader.timeoutMs).isEqualTo(60_000);
}
@Test
public void removeUserInfo_withUserInfo() {
Uri uri = Uri.parse("rtsp://user:pass@foo.bar/foo.mkv");