Escape reserved characters when converting paths to urls

* Introduce and use BUrl::BUrl(const BPath&)
* The path is url-encoded, and the protocol is set to "file"

Fixes #10964.
This commit is contained in:
Adrien Destugues 2014-06-25 10:40:51 +02:00
parent 6bcbdcc3c0
commit 158ae74373
4 changed files with 28 additions and 4 deletions

View File

@ -8,6 +8,7 @@
#include <Archivable.h>
#include <Message.h>
#include <Path.h>
#include <String.h>
@ -17,6 +18,7 @@ public:
BUrl(BMessage* archive);
BUrl(const BUrl& other);
BUrl(const BUrl& base, const BString& relative);
BUrl(const BPath& path);
BUrl();
virtual ~BUrl();

View File

@ -372,6 +372,7 @@ void
BrowserApp::_RefsReceived(BMessage* message, int32* _pagesCreated,
bool* _fullscreen)
{
puts("refs!");
int32 pagesCreated = 0;
BrowserWindow* window = NULL;
@ -390,9 +391,9 @@ BrowserApp::_RefsReceived(BMessage* message, int32* _pagesCreated,
BPath path;
if (entry.GetPath(&path) != B_OK)
continue;
BString url;
url << path.Path();
window = _CreateNewPage(url, window, fullscreen, pagesCreated == 0);
BUrl url(path);
window = _CreateNewPage(url.UrlString(), window, fullscreen,
pagesCreated == 0);
pagesCreated++;
}

View File

@ -68,6 +68,7 @@
#include <StringView.h>
#include <TextControl.h>
#include <UnicodeChar.h>
#include <Url.h>
#include <map>
#include <stdio.h>
@ -967,7 +968,9 @@ BrowserWindow::MessageReceived(BMessage* message)
BPath path;
if (!entry.Exists() || entry.GetPath(&path) != B_OK)
break;
CurrentWebView()->LoadURL(path.Path());
BUrl url(path);
CurrentWebView()->LoadURL(url);
break;
}

View File

@ -154,6 +154,24 @@ BUrl::BUrl()
}
BUrl::BUrl(const BPath& path)
:
fUrlString(),
fProtocol(),
fUser(),
fPassword(),
fHost(),
fPort(0),
fPath(),
fRequest(),
fHasHost(false),
fHasFragment(false)
{
SetUrlString(UrlEncode(path.Path(), true, true));
SetProtocol("file");
}
BUrl::~BUrl()
{
}