99x / w3c-link-validator

Command line tool, identifying broken links, validate basic html standards and reporting
https://www.npmjs.com/package/w3c-link-validator
MIT License
18 stars 11 forks source link

Fails on `mailto:` links #60

Open rondonjon opened 4 years ago

rondonjon commented 4 years ago

runValidator fails with an exception when a mailto: URL is found in the page. The application then terminates with:

internal/validators.js:112
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object
    at validateString (internal/validators.js:112:11)
    at Object.basename (path.js:1157:5)
    at runValidator (/home/eon/eon-com-relaunch/node_modules/w3c-link-validator/src/w3clink.js:72:22)
    at Request._callback (/home/eon/eon-com-relaunch/node_modules/w3c-link-validator/src/w3clink.js:120:13)
    at Request.self.callback (/home/eon/eon-com-relaunch/node_modules/request/request.js:185:22)
    at Request.emit (events.js:210:5)
    at Request.<anonymous> (/home/eon/eon-com-relaunch/node_modules/request/request.js:1161:10)
    at Request.emit (events.js:210:5)
    at IncomingMessage.<anonymous> (/home/eon/eon-com-relaunch/node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:299:28) {
  code: 'ERR_INVALID_ARG_TYPE'
}

I have been able to resolve this by replacing

var _base = path.basename(urlinfo.pathname);

with

var _base = path.basename(urlinfo.pathname || urlinfo.href);

but I haven't really tested it.