mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-01 18:35:47 +01:00
Accept more plausible URLs rather than falling back to horrid defsearch. Closes issue #338.
This commit is contained in:
@@ -1281,7 +1281,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
* @param {string} str
|
* @param {string} str
|
||||||
* @returns {string[]}
|
* @returns {string[]}
|
||||||
*/
|
*/
|
||||||
stringToURLArray: deprecated("dactyl.parseURLs", "parseURLs"),
|
|
||||||
parseURLs: function parseURLs(str) {
|
parseURLs: function parseURLs(str) {
|
||||||
let urls;
|
let urls;
|
||||||
|
|
||||||
@@ -1290,7 +1289,24 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
else
|
else
|
||||||
urls = [str];
|
urls = [str];
|
||||||
|
|
||||||
|
let re = util.regexp(<![CDATA[
|
||||||
|
^ ( <domain>+ (:\d+)? (/ .*)?) $
|
||||||
|
]]>, "g", {
|
||||||
|
domain: util.regexp(String.replace(<![CDATA[
|
||||||
|
[^
|
||||||
|
U0000-U002c // U002d-U002e --.
|
||||||
|
U002f // /
|
||||||
|
// U0030-U0039 0-9
|
||||||
|
U003a-U0040 // U0041-U005a a-z
|
||||||
|
U005b-U0060 // U0061-U007a A-Z
|
||||||
|
U007b-U007f
|
||||||
|
]
|
||||||
|
]]>, /U/g, "\\u"))
|
||||||
|
});
|
||||||
|
|
||||||
return urls.map(function (url) {
|
return urls.map(function (url) {
|
||||||
|
url = url.trim();
|
||||||
|
|
||||||
if (/^(\.{0,2}|~)(\/|$)/.test(url)) {
|
if (/^(\.{0,2}|~)(\/|$)/.test(url)) {
|
||||||
try {
|
try {
|
||||||
// Try to find a matching file.
|
// Try to find a matching file.
|
||||||
@@ -1301,35 +1317,26 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
catch (e) {}
|
catch (e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// strip each 'URL' - makes things simpler later on
|
// If it starts with a valid protocol, pass it through.
|
||||||
url = url.trim();
|
let proto = /^([-\w]+):/.exec(url);
|
||||||
|
if (proto && "@mozilla.org/network/protocol;1?name=" + proto[1] in Cc)
|
||||||
|
return url.replace(/\s+/g, "");
|
||||||
|
|
||||||
// Look for a valid protocol
|
// Check for a matching search keyword.
|
||||||
let proto = url.match(/^([-\w]+):/);
|
let searchURL = bookmarks.getSearchURL(url, false);
|
||||||
if (proto && Cc["@mozilla.org/network/protocol;1?name=" + proto[1]])
|
|
||||||
// Handle as URL, but remove spaces. Useful for copied/'p'asted URLs.
|
|
||||||
return url.replace(/\s*\n+\s*/g, "");
|
|
||||||
|
|
||||||
// Ok, not a valid proto. If it looks like URL-ish (foo.com/bar),
|
|
||||||
// let Gecko figure it out.
|
|
||||||
if (/^[a-zA-Z0-9-.]+(?:\/|$)/.test(url) && /[.\/]/.test(url) && !/\s/.test(url) || /^[a-zA-Z0-9-.]+:\d+(?:\/|$)/.test(url))
|
|
||||||
return url;
|
|
||||||
|
|
||||||
// TODO: it would be clearer if the appropriate call to
|
|
||||||
// getSearchURL was made based on whether or not the first word was
|
|
||||||
// indeed an SE alias rather than seeing if getSearchURL can
|
|
||||||
// process the call usefully and trying again if it fails
|
|
||||||
|
|
||||||
// check for a search engine match in the string, then try to
|
|
||||||
// search for the whole string in the default engine
|
|
||||||
let searchURL = bookmarks.getSearchURL(url, false) || bookmarks.getSearchURL(url, true);
|
|
||||||
if (searchURL)
|
if (searchURL)
|
||||||
return searchURL;
|
return searchURL;
|
||||||
|
|
||||||
// Hmm. No defsearch? Let the host app deal with it, then.
|
// If it looks like URL-ish (foo.com/bar), let Gecko figure it out.
|
||||||
return url;
|
if (re.test(url))
|
||||||
|
return util.createURI(url).spec;
|
||||||
|
|
||||||
|
// Pass it off to the default search engine or, failing
|
||||||
|
// that, let Gecko deal with it as is.
|
||||||
|
return bookmarks.getSearchURL(url, true) || util.createURI(url).spec;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
stringToURLArray: deprecated("dactyl.parseURLs", "parseURLs"),
|
||||||
|
|
||||||
get assert() util.assert,
|
get assert() util.assert,
|
||||||
|
|
||||||
|
|||||||
@@ -384,7 +384,7 @@ var Addons = Module("addons", {
|
|||||||
}, {
|
}, {
|
||||||
argCount: "1",
|
argCount: "1",
|
||||||
completer: function (context) {
|
completer: function (context) {
|
||||||
context.filters.push(function ({ item }) item.isDirectory() || /\.xpi$/.test(item.leafName));
|
context.filters.push(function ({ isdir, text }) isdir || /\.xpi$/.test(text));
|
||||||
completion.file(context);
|
completion.file(context);
|
||||||
},
|
},
|
||||||
literal: 0
|
literal: 0
|
||||||
|
|||||||
@@ -899,32 +899,27 @@ var Completion = Module("completion", {
|
|||||||
// depending on the 'complete' option
|
// depending on the 'complete' option
|
||||||
// if the 'complete' argument is passed like "h", it temporarily overrides the complete option
|
// if the 'complete' argument is passed like "h", it temporarily overrides the complete option
|
||||||
url: function url(context, complete) {
|
url: function url(context, complete) {
|
||||||
let numLocationCompletions = 0; // how many async completions did we already return to the caller?
|
|
||||||
let start = 0;
|
|
||||||
let skip = 0;
|
|
||||||
|
|
||||||
if (this.options["urlseparator"])
|
if (this.options["urlseparator"])
|
||||||
skip = context.filter.match("^.*" + this.options["urlseparator"]); // start after the last 'urlseparator'
|
var skip = RegExp("^.*" + this.options["urlseparator"] + "\\s*").exec(context.filter);
|
||||||
|
|
||||||
if (skip)
|
if (skip)
|
||||||
context.advance(skip[0].length);
|
context.advance(skip[0].length);
|
||||||
|
|
||||||
if (complete == null)
|
if (/^about:/.test(context.filter))
|
||||||
complete = this.options["complete"];
|
|
||||||
|
|
||||||
if (/^about:/.test(context.filter)) {
|
|
||||||
context.fork("about", 6, this, function (context) {
|
context.fork("about", 6, this, function (context) {
|
||||||
context.generate = function () {
|
context.generate = function () {
|
||||||
const PREFIX = "@mozilla.org/network/protocol/about;1?what=";
|
const PREFIX = "@mozilla.org/network/protocol/about;1?what=";
|
||||||
return [[k.substr(PREFIX.length), ""] for (k in Cc) if (k.indexOf(PREFIX) == 0)];
|
return [[k.substr(PREFIX.length), ""] for (k in Cc) if (k.indexOf(PREFIX) == 0)];
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
if (complete == null)
|
||||||
|
complete = this.options["complete"];
|
||||||
|
|
||||||
// Will, and should, throw an error if !(c in opts)
|
// Will, and should, throw an error if !(c in opts)
|
||||||
Array.forEach(complete, function (c) {
|
Array.forEach(complete, function (c) {
|
||||||
let completer = this.urlCompleters[c];
|
let completer = this.urlCompleters[c];
|
||||||
context.fork.apply(context, [c, 0, this, completer.completer].concat(completer.args));
|
context.forkapply(c, 0, this, completer.completer, completer.args);
|
||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user