summaryrefslogtreecommitdiffstats
path: root/lib/utils
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@friendco.de>2014-06-17 10:56:13 -0700
committerAaron O'Mullan <aaron.omullan@friendco.de>2014-06-17 10:56:13 -0700
commit04c025774d9e974bf2f4d4ec2422867c7c239b40 (patch)
tree595ddaea3c7543d3d4dc75ae1d808368421b2f38 /lib/utils
parent80aac7f58129e028adce30bee2e64f7a39f4d843 (diff)
downloadgitbook-04c025774d9e974bf2f4d4ec2422867c7c239b40.zip
gitbook-04c025774d9e974bf2f4d4ec2422867c7c239b40.tar.gz
gitbook-04c025774d9e974bf2f4d4ec2422867c7c239b40.tar.bz2
Improve robustness of link utility functions
Fixes #321, fixes #323
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/links.js14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/utils/links.js b/lib/utils/links.js
index 6606bbf..b4d2fb7 100644
--- a/lib/utils/links.js
+++ b/lib/utils/links.js
@@ -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] != '/';
+ } catch(err) {}
- return !parsed.protocol && parsed.path && parsed.path[0] != '/';
+ return true;
};
// Relative to absolute path