From 9ea3762ca1276b89754a66c5687720f7404e1ed8 Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Wed, 29 Jan 2014 14:52:02 +0000 Subject: [PATCH] Fixed ToFileURL. Turns out all that encoding stuff is unnecessary anyway, the browsers (IE, Chrome, Firefox tested) just interpret it right anyway. Tested with a Unicode path, part of issue #94 work. --- src/backend/helpers.cpp | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/backend/helpers.cpp b/src/backend/helpers.cpp index eacf3ef7..c0ada1a0 100644 --- a/src/backend/helpers.cpp +++ b/src/backend/helpers.cpp @@ -229,27 +229,7 @@ namespace boss { //Turns an absolute filesystem path into a valid file:// URL. std::string ToFileURL(const fs::path& file) { BOOST_LOG_TRIVIAL(trace) << "Converting file path " << file << " to a URL."; - //URLs are UTF-8 encoded then any characters (equiv. their corresponding bytes) not in the unreserved set (equiv. their corresponding bytes) are replaced by a percentage sign followed by the hex representation of their binary value. - string unreserved = "-.0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~"; //Unreserved in byte value order, plus the colon character since that's allowed for drive paths. - - string url = "file:///"; - for (boost::filesystem::path::const_iterator it=file.begin(), endit=file.end(); it != endit; ++it) { - string part = it->string(); - if (part == "/") //Skip exta backslash after drive path. - continue; - //String iterator is byte-by-byte, not character-by-character, which is good. - for (string::const_iterator jt=part.begin(), endjt=part.end(); jt != endjt; ++jt) { - if (!binary_search(unreserved.begin(), unreserved.end(), *jt)) - //Replace with percentage-hex value. - url += '%' + IntToHexString(*jt); - else - url += *jt; - } - url += '/'; - } - url.resize(url.length()-1); //Get rid of trailing forward slash. - - return url; + return "file:///" + file.string(); //Seems that we don't need to worry about encoding, tested with Unicode paths. } std::string GetLangString(const unsigned int num) {