Improve robustness of link utility functions

Fixes #321, fixes #323
This commit is contained in:
Aaron O'Mullan
2014-06-17 10:56:13 -07:00
parent 80aac7f581
commit 04c025774d
+11 -3
View File
@@ -3,14 +3,22 @@ var path = require('path');
// Is the link an external link
var isExternal = function(href) {
return Boolean(url.parse(href).protocol);
try {
return Boolean(url.parse(href).protocol);
} catch(err) { }
return false;
};
// Return true if the link is relative
var isRelative = function(href) {
var parsed = url.parse(href);
try {
var parsed = url.parse(href);
return !parsed.protocol && parsed.path && parsed.path[0] != '/';
return !parsed.protocol && parsed.path && parsed.path[0] != '/';
} catch(err) {}
return true;
};
// Relative to absolute path