Remove some redundant fields

These were getting out of sync and causing trouble, and they are easy to
compute from existing information.

Fixes some problems detected by the testsuite where the user/password or
the host would sometime disappear from the URL.
This commit is contained in:
Adrien Destugues
2014-06-04 11:56:23 +02:00
parent 3fd76758ed
commit cd805f6793
2 changed files with 19 additions and 20 deletions
+2 -2
View File
@@ -89,6 +89,8 @@ public:
private: private:
void _ResetFields(); void _ResetFields();
void _ExplodeUrlString(const BString& urlString); void _ExplodeUrlString(const BString& urlString);
BString _MergePath(const BString& relative) const;
void _SetPathUnsafe(const BString& path);
static BString _DoUrlEncodeChunk(const BString& chunk, static BString _DoUrlEncodeChunk(const BString& chunk,
bool strict, bool directory = false); bool strict, bool directory = false);
@@ -121,10 +123,8 @@ private:
bool fHasProtocol : 1; bool fHasProtocol : 1;
bool fHasUserName : 1; bool fHasUserName : 1;
bool fHasPassword : 1; bool fHasPassword : 1;
bool fHasUserInfo : 1;
bool fHasHost : 1; bool fHasHost : 1;
bool fHasPort : 1; bool fHasPort : 1;
bool fHasAuthority : 1;
bool fHasPath : 1; bool fHasPath : 1;
bool fHasRequest : 1; bool fHasRequest : 1;
bool fHasFragment : 1; bool fHasFragment : 1;
+17 -18
View File
@@ -30,7 +30,7 @@ BUrl::BUrl(const char* url)
fPort(0), fPort(0),
fPath(), fPath(),
fRequest(), fRequest(),
fHasAuthority(false), fHasHost(false),
fHasFragment(false) fHasFragment(false)
{ {
SetUrlString(url); SetUrlString(url);
@@ -47,7 +47,7 @@ BUrl::BUrl(BMessage* archive)
fPort(0), fPort(0),
fPath(), fPath(),
fRequest(), fRequest(),
fHasAuthority(false), fHasHost(false),
fHasFragment(false) fHasFragment(false)
{ {
BString url; BString url;
@@ -70,7 +70,7 @@ BUrl::BUrl(const BUrl& other)
fPort(0), fPort(0),
fPath(), fPath(),
fRequest(), fRequest(),
fHasAuthority(false), fHasHost(false),
fHasFragment(false) fHasFragment(false)
{ {
*this = other; *this = other;
@@ -87,7 +87,7 @@ BUrl::BUrl(const BUrl& base, const BString& location)
fPort(0), fPort(0),
fPath(), fPath(),
fRequest(), fRequest(),
fHasAuthority(false), fHasHost(false),
fHasFragment(false) fHasFragment(false)
{ {
// This implements the algorithm in RFC3986, Section 5.2. // This implements the algorithm in RFC3986, Section 5.2.
@@ -142,7 +142,7 @@ BUrl::BUrl()
fPort(0), fPort(0),
fPath(), fPath(),
fRequest(), fRequest(),
fHasAuthority(false), fHasHost(false),
fHasFragment(false) fHasFragment(false)
{ {
_ResetFields(); _ResetFields();
@@ -465,7 +465,7 @@ BUrl::HasProtocol() const
bool bool
BUrl::HasAuthority() const BUrl::HasAuthority() const
{ {
return fHasAuthority; return fHasHost || fHasUserName;
} }
@@ -486,7 +486,7 @@ BUrl::HasPassword() const
bool bool
BUrl::HasUserInfo() const BUrl::HasUserInfo() const
{ {
return fHasUserInfo; return fHasUserName || fHasPassword;
} }
@@ -641,10 +641,8 @@ BUrl::operator=(const BUrl& other)
fHasProtocol = other.fHasProtocol; fHasProtocol = other.fHasProtocol;
fHasUserName = other.fHasUserName; fHasUserName = other.fHasUserName;
fHasPassword = other.fHasPassword; fHasPassword = other.fHasPassword;
fHasUserInfo = other.fHasUserInfo;
fHasHost = other.fHasHost; fHasHost = other.fHasHost;
fHasPort = other.fHasPort; fHasPort = other.fHasPort;
fHasAuthority = other.fHasAuthority;
fHasPath = other.fHasPath; fHasPath = other.fHasPath;
fHasRequest = other.fHasRequest; fHasRequest = other.fHasRequest;
fHasFragment = other.fHasFragment; fHasFragment = other.fHasFragment;
@@ -684,10 +682,8 @@ BUrl::_ResetFields()
fHasProtocol = false; fHasProtocol = false;
fHasUserName = false; fHasUserName = false;
fHasPassword = false; fHasPassword = false;
fHasUserInfo = false;
fHasHost = false; fHasHost = false;
fHasPort = false; fHasPort = false;
fHasAuthority = false;
fHasPath = false; fHasPath = false;
fHasRequest = false; fHasRequest = false;
fHasFragment = false; fHasFragment = false;
@@ -737,8 +733,12 @@ BUrl::_ExplodeUrlString(const BString& url)
url.CopyInto(fAuthority, match.GroupStartOffsetAt(3), url.CopyInto(fAuthority, match.GroupStartOffsetAt(3),
match.GroupEndOffsetAt(3) - match.GroupStartOffsetAt(3)); match.GroupEndOffsetAt(3) - match.GroupStartOffsetAt(3));
SetAuthority(fAuthority); SetAuthority(fAuthority);
} else } else {
fHasAuthority = false; fHasHost = false;
fHasPort = false;
fHasUserName = false;
fHasPassword = false;
}
// Path // Path
url.CopyInto(fPath, match.GroupStartOffsetAt(4), url.CopyInto(fPath, match.GroupStartOffsetAt(4),
@@ -806,14 +806,15 @@ BUrl::SetAuthority(const BString& authority)
fAuthority = authority; fAuthority = authority;
fHasPort = false; fHasPort = false;
fHasUserInfo = false; fHasUserName = false;
fHasHost = false; fHasPassword = false;
// An empty authority is still an authority, making it possible to have // An empty authority is still an authority, making it possible to have
// URLs such as file:///path/to/file. // URLs such as file:///path/to/file.
// TODO however, there is no way to unset the authority once it is set... // TODO however, there is no way to unset the authority once it is set...
// We may want to take a const char* parameter and allow NULL. // We may want to take a const char* parameter and allow NULL.
fHasAuthority = true; fHasHost = true;
if (fAuthority.IsEmpty()) if (fAuthority.IsEmpty())
return; return;
@@ -837,8 +838,6 @@ BUrl::SetAuthority(const BString& authority)
} else { } else {
SetUserName(fUser); SetUserName(fUser);
} }
fHasUserInfo = true;
} }