Browse Source

Always use absolute path for file:// scheme

pull/2/head
tomleb 5 years ago
parent
commit
a4139dcd1c
  1. 8
      src/URL.cpp
  2. 19
      src/main.cpp

8
src/URL.cpp

@ -210,10 +210,18 @@ std::tuple<std::unique_ptr<URL>,enum URIParseError> parseUri(std::string raw) { @@ -210,10 +210,18 @@ std::tuple<std::unique_ptr<URL>,enum URIParseError> parseUri(std::string raw) {
}
}
}
/*
* File scheme allows a host (ie: file://<host>/<path>)
* If the host is empty then be default to localhost
*/
if (uri->host.length() == 0 && uri->scheme == "file") {
uri->host = "127.0.0.1";
}
return std::make_tuple(std::move(uri), URI_PARSE_ERROR_NONE);
}
// Why do we need this ? -tomleb
URL::URL() {
scheme = "";
userinfo = "";

19
src/main.cpp

@ -27,6 +27,11 @@ bool setWindowContent(URL const& url) { @@ -27,6 +27,11 @@ bool setWindowContent(URL const& url) {
return true;
}
bool isAbsolutePath(const std::string s);
bool isAbsolutePath(const std::string s) {
return (s.length() > 0 && s[0] == '/');
}
int main(int argc, char *argv[]) {
if (argc == 1) {
std::cout << "./netrunner <url|file.html> [-log <error|warning|notice|info|debug>]" << std::endl;
@ -35,10 +40,16 @@ int main(int argc, char *argv[]) { @@ -35,10 +40,16 @@ int main(int argc, char *argv[]) {
std::cout << "/g/ntr - NetRunner build " << __DATE__ << std::endl;
initCLParams(argc, argv);
std::string url = getCLParamByIndex(1);
std::string rawUrl = getCLParamByIndex(1);
// if we do this here, shouldn't we do this in parseUri too?
if (url.find("://") == url.npos) {
url = "file://" + url;
if (rawUrl.find("://") == rawUrl.npos) {
// Path should always be absolute for file://
if (isAbsolutePath(rawUrl)) {
rawUrl = "file://" + rawUrl;
} else {
rawUrl = "file://" + std::string(getenv("PWD")) + '/' + rawUrl;
std::cout << rawUrl << std::endl;
}
}
// we need to set up OGL before we can setDOM (because component can't be constructed (currently) without OGL)
@ -49,7 +60,7 @@ int main(int argc, char *argv[]) { @@ -49,7 +60,7 @@ int main(int argc, char *argv[]) {
}
//logDebug() << "pre URL parse [" << url << "]" << std::endl;
window->currentURL=URL(url);
window->currentURL=URL(rawUrl);
logDebug() << "loading [" << window->currentURL << "]" << std::endl;
if (!setWindowContent(window->currentURL)) {

Loading…
Cancel
Save