Skip to content

Commit

Permalink
Escape reserved characters when converting paths to urls
Browse files Browse the repository at this point in the history
* Introduce and use BUrl::BUrl(const BPath&)
* The path is url-encoded, and the protocol is set to "file"

Fixes #10964.
  • Loading branch information
pulkomandy committed Jun 25, 2014
1 parent 6bcbdcc commit 158ae74
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 2 additions & 0 deletions headers/os/net/Url.h
Expand Up @@ -8,6 +8,7 @@

#include <Archivable.h>
#include <Message.h>
#include <Path.h>
#include <String.h>


Expand All @@ -17,6 +18,7 @@ class BUrl : public BArchivable {
BUrl(BMessage* archive);
BUrl(const BUrl& other);
BUrl(const BUrl& base, const BString& relative);
BUrl(const BPath& path);
BUrl();
virtual ~BUrl();

Expand Down
7 changes: 4 additions & 3 deletions src/apps/webpositive/BrowserApp.cpp
Expand Up @@ -372,6 +372,7 @@ void
BrowserApp::_RefsReceived(BMessage* message, int32* _pagesCreated,
bool* _fullscreen)
{
puts("refs!");
int32 pagesCreated = 0;

BrowserWindow* window = NULL;
Expand All @@ -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++;
}

Expand Down
5 changes: 4 additions & 1 deletion src/apps/webpositive/BrowserWindow.cpp
Expand Up @@ -68,6 +68,7 @@
#include <StringView.h>
#include <TextControl.h>
#include <UnicodeChar.h>
#include <Url.h>

#include <map>
#include <stdio.h>
Expand Down Expand Up @@ -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;
}

Expand Down
18 changes: 18 additions & 0 deletions src/kits/network/libnetapi/Url.cpp
Expand Up @@ -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()
{
}
Expand Down

0 comments on commit 158ae74

Please sign in to comment.