issue212: [patch] Allow paste-url with addresses without http://, e.g. with www.domain.com

Priority: wish Status: resolved
Messages
msg461 (view) Author: dclemente Date: 2009-10-15.14:55:44
Now paste-url says „malformed URL“ if you had copied www.domain.com because it needs http://www.domain.com

This patch allows to paste www.domain.com too
Spaces are trimmed so that you can also paste "   www.domain.com " and it works.

diff --git a/modules/element.js b/modules/element.js
index 3022210..f569b80 100644
--- a/modules/element.js
+++ b/modules/element.js
@@ -154,10 +154,17 @@ define_browser_object_class("paste-url",
     "Browser object which reads an url from the X Primary Selection, "+
     "falling back on the clipboard for operating systems which lack one.",
     function (I, prompt) {
+		var url = read_from_x_primary_selection();
+		// trim spaces
+		url = url.replace(/^\s*|\s*$/,"");
+		// add http:// if needed
+		if (url.match(/^[^:]+\./)) {
+			url = "http://" + url;
+		}
         try {
-            return make_uri(read_from_x_primary_selection()).spec;
+            return make_uri(url).spec;
         } catch (e) {
-            throw new interactive_error("error: malformed url");
+            throw new interactive_error("error: malformed url: "+url);
         }
     });
msg463 (view) Author: retroj Date: 2009-10-15.20:49:32
thanks
History
Date User Action Args
2009-10-15 20:50:18retrojsetstatus: chatting -> resolved
2009-10-15 20:49:32retrojsetstatus: unread -> chatting
messages: + msg463
2009-10-15 14:55:44dclementecreate