Skip to content
This repository was archived by the owner on May 7, 2018. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ function validate(input, callback) {
return validate.validateSigned(input, callback);
if (isUrl(input))
return validate.validateHostedUrl(input, callback);
if (isJson(input))
var url = urlFromAssertion(JSON.parse(input));
if (url)
return validate.validateHostedUrl(url, callback, '');
return callback(makeError('input', 'not a valid signed badge or url', { input: input }));
}
return callback(makeError('input', 'input must be a string or object', { input: input }));
Expand Down Expand Up @@ -541,6 +545,19 @@ function getInternalClass(thing) {
return Object.prototype.toString.call(thing);
}

function isJson (str) {
try { JSON.parse(str); return true } catch(e) { return false }
}

function urlFromAssertion (json) {
try {
var url = json.verify.url;
if (isUrl(url))
return url;
return false;
} catch(e) { return false; }
}

const isUrl = regexToValidator(re.url, 'must be a URL');
const isAbsoluteUrl = regexToValidator(re.absoluteUrl, 'must be an absolute URL');
const isEmail = regexToValidator(re.email, 'must be an email address');
Expand Down