hterm: support URIs w/out authorities
Some URI schemes like mailto do not use double slashes because they lack
an authority (a URI term). That means this URI is valid:
mailto:vapier@chromium.org
But this URI is not valid:
mailto://vapier@chromium.org
Start a whitelist for known URI schemes that fall into this bucket so we
don't incorrectly prefix them with http://.
Change-Id: I4db5650eba87bf0f4ab56d14141d0c1676912159
Reviewed-on: https://chromium-review.googlesource.com/549119
Reviewed-by: Brandon Gilmore <varz@google.com>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/hterm/js/hterm_terminal.js b/hterm/js/hterm_terminal.js
index aa31ce2..f462fa0 100644
--- a/hterm/js/hterm_terminal.js
+++ b/hterm/js/hterm_terminal.js
@@ -2945,10 +2945,20 @@
// Make sure URL is valid before opening.
if (str.length > 2048 || str.search(/[\s\[\](){}<>"'\\^`]/) >= 0)
return;
- // If the URL isn't anchored, it'll open relative to the extension.
+
+ // If the URI isn't anchored, it'll open relative to the extension.
// We have no way of knowing the correct schema, so assume http.
- if (str.search('^[a-zA-Z][a-zA-Z0-9+.-]*://') < 0)
- str = 'http://' + str;
+ if (str.search('^[a-zA-Z][a-zA-Z0-9+.-]*://') < 0) {
+ // We have to whitelist a few protocols that lack authorities and thus
+ // never use the //. Like mailto.
+ switch (str.split(':', 1)[0]) {
+ case 'mailto':
+ break;
+ default:
+ str = 'http://' + str;
+ break;
+ }
+ }
this.openUrl(str);
}