From 4dffc2a9c1608cec7a30b1330e30252cf35468cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?= <grubba@grubba.org> Date: Wed, 8 Jun 2016 15:31:44 +0200 Subject: [PATCH] Standards.URI: Improved handling of non-paths in combine_uri_path(). This avoids prefixing the path with a slash in eg: Standards.URI("<foo@example.com>", "mailto:<bar@example.com>"); --- lib/modules/Standards.pmod/URI.pike | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/modules/Standards.pmod/URI.pike b/lib/modules/Standards.pmod/URI.pike index 91abe14e7d..b698472162 100644 --- a/lib/modules/Standards.pmod/URI.pike +++ b/lib/modules/Standards.pmod/URI.pike @@ -116,7 +116,7 @@ int `==(mixed something) && other->fragment == fragment; } -string combine_uri_path(string base, string rel) +string combine_uri_path(string base, string rel, int(0..1)|void is_abs_path) { string buf = rel; array segments; @@ -136,7 +136,11 @@ string combine_uri_path(string base, string rel) // copied to the buffer. In other words, any characters after the // last (right-most) slash character, if any, are excluded. segments = base/"/"; - buf = segments[..<1]*"/"+"/"; + if ((sizeof(segments) > 1) || is_abs_path) { + buf = segments[..<1]*"/"+"/"; + } else { + buf = ""; + } // b) The reference's path component is appended to the buffer string. buf += rel; @@ -371,8 +375,10 @@ void reparse_uri(this_program|string|void base_uri) DEBUG("Combining base path %O with path %O => %O", this::base_uri->path, path, - combine_uri_path(this::base_uri->path, path)); - path = combine_uri_path(this::base_uri->path, path); + combine_uri_path(this::base_uri->path, path, + !!this::base_uri->authority)); + path = combine_uri_path(this::base_uri->path, path, + !!this::base_uri->authority); } } -- GitLab