File tree Expand file tree Collapse file tree 2 files changed +17
-12
lines changed
Expand file tree Collapse file tree 2 files changed +17
-12
lines changed Original file line number Diff line number Diff 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
5356TEST_F (UtilsTest, JoinUrls)
Original file line number Diff line number Diff 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 " " ;
You can’t perform that action at this time.
0 commit comments