From 158ae743734bb0a3900702317943df71586fbce4 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Wed, 25 Jun 2014 10:40:51 +0200 Subject: [PATCH] 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. --- headers/os/net/Url.h | 2 ++ src/apps/webpositive/BrowserApp.cpp | 7 ++++--- src/apps/webpositive/BrowserWindow.cpp | 5 ++++- src/kits/network/libnetapi/Url.cpp | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/headers/os/net/Url.h b/headers/os/net/Url.h index 06dc6047483..0363989ef87 100644 --- a/headers/os/net/Url.h +++ b/headers/os/net/Url.h @@ -8,6 +8,7 @@ #include #include +#include #include @@ -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(); diff --git a/src/apps/webpositive/BrowserApp.cpp b/src/apps/webpositive/BrowserApp.cpp index bd419eaa73d..5243513780c 100644 --- a/src/apps/webpositive/BrowserApp.cpp +++ b/src/apps/webpositive/BrowserApp.cpp @@ -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++; } diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index c177aa0b784..7b25f9213c5 100644 --- a/src/apps/webpositive/BrowserWindow.cpp +++ b/src/apps/webpositive/BrowserWindow.cpp @@ -68,6 +68,7 @@ #include #include #include +#include #include #include @@ -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; } diff --git a/src/kits/network/libnetapi/Url.cpp b/src/kits/network/libnetapi/Url.cpp index a32d1477202..fb1d499aaea 100644 --- a/src/kits/network/libnetapi/Url.cpp +++ b/src/kits/network/libnetapi/Url.cpp @@ -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() { }