summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBradley Farias <bradley.meck@gmail.com>2017-07-31 17:02:23 -0500
committerBradley Farias <bradley.meck@gmail.com>2017-07-31 17:02:23 -0500
commit375d4a7385544d9a85de77e8fbbecebf0d5e6861 (patch)
treecf0d6e42296b8ae2cbcaccafc0f19f3c3f3b9ba3 /src
parent48d3401f195a3127c6343f364d92ea038e135e48 (diff)
downloadnode-new-pull/14369/head.tar.gz
properly decode url encoding in pathnamespull/14369/head
Diffstat (limited to 'src')
-rw-r--r--src/module_wrap.cc2
-rw-r--r--src/node_url.cc11
-rw-r--r--src/node_url.h2
3 files changed, 14 insertions, 1 deletions
diff --git a/src/module_wrap.cc b/src/module_wrap.cc
index 1342fd0393..ca4e22b0e7 100644
--- a/src/module_wrap.cc
+++ b/src/module_wrap.cc
@@ -332,7 +332,7 @@ inline const struct file_check check_file(URL search,
bool allow_dir = false) {
struct file_check ret;
uv_fs_t fs_req;
- uv_fs_open(nullptr, &fs_req, search.path().c_str(), O_RDONLY, 0, nullptr);
+ uv_fs_open(nullptr, &fs_req, search.decoded_path().c_str(), O_RDONLY, 0, nullptr);
auto fd = fs_req.result;
if (fd < 0) {
return ret;
diff --git a/src/node_url.cc b/src/node_url.cc
index 75f262bad5..d961b9ede0 100644
--- a/src/node_url.cc
+++ b/src/node_url.cc
@@ -886,6 +886,17 @@ static url_host_type ParseHost(url_host* host,
return type;
}
+std::string node::url::URL::decoded_path() {
+ std::string ret;
+ for (auto i = context_.path.begin(); i != context_.path.end(); i++) {
+ ret += '/';
+ std::string tmp;
+ PercentDecode(i->c_str(), i->length(), &tmp);
+ ret += tmp;
+ }
+ return ret;
+}
+
// Locates the longest sequence of 0 segments in an IPv6 address
// in order to use the :: compression when serializing
static inline uint16_t* FindLongestZeroSequence(uint16_t* values,
diff --git a/src/node_url.h b/src/node_url.h
index 72ac366ec1..fbe7683a49 100644
--- a/src/node_url.h
+++ b/src/node_url.h
@@ -163,6 +163,8 @@ class URL {
return ret;
}
+ std::string decoded_path();
+
const Local<Value> ToObject(Environment* env) const;
private: