BUrl: rework handling of URL encoding
The content of a BUrl should always be in encoded form, to simplify handling and validation. Deprecate the UrlEncode member function and make it private. Instead aadd a new way to handle URL encoding: - All ways to set an URL (constructors, SetUrlString, and all setters) now take an extra boolean parameter indicating if the string is already encoded. The default value is to encode strings automatically. - The static version of UrlEncode and UrlDecode, which operate on a string, are preserved and used by other parts of the API. All unit tests adjusted to handle this, and still passing. Fixes #12983 Change-Id: I06f06978d0d35e56d7c92b67f001856bb7dcafc8 Reviewed-on: https://review.haiku-os.org/c/haiku/+/1193 Reviewed-by: nephele nephele <[email protected]> Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
60bb9a9f96
commit
1d242620b4
@@ -14,7 +14,7 @@
|
||||
|
||||
class BUrl : public BArchivable {
|
||||
public:
|
||||
BUrl(const char* url);
|
||||
BUrl(const char* url, bool encode = true);
|
||||
BUrl(BMessage* archive);
|
||||
BUrl(const BUrl& other);
|
||||
BUrl(const BUrl& base, const BString& relative);
|
||||
@@ -23,7 +23,8 @@ public:
|
||||
virtual ~BUrl();
|
||||
|
||||
// URL fields modifiers
|
||||
BUrl& SetUrlString(const BString& url);
|
||||
BUrl& SetUrlString(const BString& url,
|
||||
bool encode = true);
|
||||
BUrl& SetProtocol(const BString& scheme);
|
||||
BUrl& SetUserName(const BString& user);
|
||||
BUrl& SetPassword(const BString& password);
|
||||
@@ -60,10 +61,6 @@ public:
|
||||
bool HasRequest() const;
|
||||
bool HasFragment() const;
|
||||
|
||||
// Url encoding/decoding of needed fields
|
||||
void UrlEncode(bool strict = false);
|
||||
void UrlDecode(bool strict = false);
|
||||
|
||||
status_t IDNAToAscii();
|
||||
status_t IDNAToUnicode();
|
||||
|
||||
@@ -98,6 +95,12 @@ public:
|
||||
operator const char*() const;
|
||||
|
||||
private:
|
||||
// Deprecated methods, use the new constructor with bool parameter
|
||||
explicit BUrl(const char* url);
|
||||
void SetUrlString(const BString& url);
|
||||
void UrlEncode(bool strict = false);
|
||||
void UrlDecode(bool strict = false);
|
||||
|
||||
void _ResetFields();
|
||||
bool _ContainsDelimiter(const BString& url);
|
||||
status_t _ExplodeUrlString(const BString& urlString,
|
||||
|
||||
Reference in New Issue
Block a user