@@ -28,10 +28,10 @@ extern "C" {
2828
2929namespace
3030{
31- // The source as it may be shown: a URL loses the user name and password
32- // it carries in front of its host, since error messages end up in logs .
33- // Anything that is not a URL with credentials is returned as it is .
34- std::string WithoutCredentials (const std::string & source)
31+ // Error messages end up in logs. URLs expose only their scheme, host
32+ // and port: credentials can also be carried in paths, queries or fragments .
33+ // Local paths without a URL scheme remain useful for diagnosing file errors .
34+ std::string SourceForError (const std::string & source)
3535 {
3636 const size_t scheme_end = source.find (" ://" );
3737
@@ -41,14 +41,12 @@ namespace
4141
4242 const size_t authority_start = scheme_end + 3 ;
4343 const size_t authority_end = source.find_first_of (" /?#" , authority_start);
44- const size_t at = source.rfind (' @' , authority_end == std::string::npos
45- ? std::string::npos : authority_end - 1 );
44+ const std::string authority = source.substr (authority_start,
45+ authority_end == std::string::npos ? std::string::npos : authority_end - authority_start);
46+ const size_t at = authority.rfind (' @' );
4647
47- if (at == std::string::npos || at < authority_start) {
48- return source;
49- }
50-
51- return source.substr (0 , authority_start) + source.substr (at + 1 );
48+ return source.substr (0 , authority_start)
49+ + (at == std::string::npos ? authority : authority.substr (at + 1 ));
5250 }
5351
5452 ffmpeg::MediaReader * ReaderOf (JNIEnv * env, jlong handle)
@@ -99,7 +97,7 @@ JNIEXPORT jlong JNICALL Java_dev_onvoid_webrtc_media_player_MediaReader_open
9997 if (result < 0 ) {
10098 reader.reset ();
10199
102- ffmpeg::ThrowIOException (env, " Opening '" + WithoutCredentials (url) + " ' failed: " + ffmpeg::ErrorText (result));
100+ ffmpeg::ThrowIOException (env, " Opening '" + SourceForError (url) + " ' failed: " + ffmpeg::ErrorText (result));
103101
104102 return 0 ;
105103 }
0 commit comments