Skip to content

Commit 2364435

Browse files
authored
Merge pull request #1799 from CastagnaIT/fix_baseurl_omega
[backport][UrlUtils] Fix GetBaseDomain for SMIL URLs
2 parents e01b456 + 75d6343 commit 2364435

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/test/TestUtils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ TEST_F(UtilsTest, DetermineBaseDomain)
4848

4949
url = "https://www.foo.bar:1234/mpd/test.mpd?ping=pong";
5050
EXPECT_EQ(URL::GetBaseDomain(url), "https://www.foo.bar");
51+
52+
url = "https://www.foo.bar/example/smil:rtmp.smil/playlist.m3u8?ping=pong";
53+
EXPECT_EQ(URL::GetBaseDomain(url), "https://www.foo.bar");
5154
}
5255

5356
TEST_F(UtilsTest, JoinUrls)

src/utils/UrlUtils.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,18 +257,20 @@ std::string UTILS::URL::GetBaseDomain(std::string url)
257257
if (paramsPos != std::string::npos)
258258
url.erase(paramsPos);
259259

260-
const size_t domainStartPos = url.find("://") + 3;
261-
// Try remove url port number and path
262-
const size_t port = url.find_first_of(':', domainStartPos);
263-
if (port != std::string::npos)
264-
url.erase(port);
265-
else
266-
{
267-
// Try remove the path
268-
const size_t slashPos = url.find_first_of('/', domainStartPos);
269-
if (slashPos != std::string::npos)
270-
url.erase(slashPos);
271-
}
260+
const size_t schemeEndPos = url.find("://");
261+
if (schemeEndPos == std::string::npos)
262+
return ""; // Not valid
263+
264+
const size_t domainStartPos = schemeEndPos + 3;
265+
const size_t portPos = url.find_first_of(':', domainStartPos);
266+
const size_t pathPos = url.find_first_of('/', domainStartPos);
267+
268+
size_t endPos = url.size();
269+
if (portPos != std::string::npos && portPos < pathPos)
270+
url.erase(portPos); // remove port number
271+
else if (pathPos != std::string::npos)
272+
url.erase(pathPos); // remove from slash
273+
272274
return url;
273275
}
274276
return "";

0 commit comments

Comments
 (0)