diff --git a/lib/marked.js b/lib/marked.js
index 196b2b9259..49a4153a4b 100644
--- a/lib/marked.js
+++ b/lib/marked.js
@@ -1426,11 +1426,18 @@ function resolveUrl(base, href) {
}
}
base = baseUrls[' ' + base];
+ var relativeBase = base.indexOf(':') === -1;
if (href.slice(0, 2) === '//') {
- return base.replace(/:[\s\S]*/, ':') + href;
+ if (relativeBase) {
+ return href;
+ }
+ return base.replace(/^([^:]+:)[\s\S]*$/, '$1') + href;
} else if (href.charAt(0) === '/') {
- return base.replace(/(:\/*[^/]*)[\s\S]*/, '$1') + href;
+ if (relativeBase) {
+ return href;
+ }
+ return base.replace(/^([^:]+:\/*[^/]*)[\s\S]*$/, '$1') + href;
} else {
return base + href;
}
diff --git a/test/specs/new/relative_base_urls.html b/test/specs/new/relative_base_urls.html
new file mode 100644
index 0000000000..6f94843f56
--- /dev/null
+++ b/test/specs/new/relative_base_urls.html
@@ -0,0 +1,35 @@
+
Absolutization of RFC 3986 URIs
+
+Absolute URI
+
+
+
+Network-path reference
+
+
+
+Absolute path
+
+
+
+Relative path
+
+
+
+Dot-relative path
+
+
+
+
+
+Same-document query
+
+
+
+Same-document fragment
+
+
+
+Empty
+
+section 4.2
diff --git a/test/specs/new/relative_base_urls.md b/test/specs/new/relative_base_urls.md
new file mode 100644
index 0000000000..1f59f1feb5
--- /dev/null
+++ b/test/specs/new/relative_base_urls.md
@@ -0,0 +1,30 @@
+---
+baseUrl: "/base/"
+---
+# Absolutization of RFC 3986 URIs
+
+## Absolute URI
+[](http://example.com/)
+
+## Network-path reference
+[](//example.com/)
+
+## Absolute path
+[](/path/to/content)
+
+## Relative path
+[](content)
+
+## Dot-relative path
+[](./content)
+
+[](../content)
+
+## Same-document query
+[](?)
+
+## Same-document fragment
+[](#)
+
+## Empty
+[section 4.2]()