tcort / markdown-link-check

checks all of the hyperlinks in a markdown text to determine if they are alive or dead
ISC License
568 stars 115 forks source link

URIError: URI malformed #211

Open NorthboundTrain opened 2 years ago

NorthboundTrain commented 2 years ago

OS: MacOS 12.4 markdown-link-check: 3.10.0 node: v16.15.1

I'm getting the following error with no indication where the issue is:

$ markdown-link-check -v -p ./docs/foo.md

FILE: ./docs/foo.md
Checking... [======================   ] 87%/opt/local/lib/node_modules/markdown-link-check/node_modules/link-check/lib/proto/http.js:37
        const url = encodeURI(decodeURIComponent(new URL(link, opts.baseUrl).toString()));
                              ^

URIError: URI malformed
    at decodeURIComponent (<anonymous>)
    at Object.check (/opt/local/lib/node_modules/markdown-link-check/node_modules/link-check/lib/proto/http.js:37:31)
    at linkCheck (/opt/local/lib/node_modules/markdown-link-check/node_modules/link-check/index.js:29:25)
    at /opt/local/lib/node_modules/markdown-link-check/index.js:118:9
    at /opt/local/lib/node_modules/markdown-link-check/node_modules/async/dist/async.js:246:13
    at replenish (/opt/local/lib/node_modules/markdown-link-check/node_modules/async/dist/async.js:446:21)
    at iterateeCallback (/opt/local/lib/node_modules/markdown-link-check/node_modules/async/dist/async.js:430:21)
    at /opt/local/lib/node_modules/markdown-link-check/node_modules/async/dist/async.js:327:20
    at /opt/local/lib/node_modules/markdown-link-check/node_modules/async/dist/async.js:248:17
    at /opt/local/lib/node_modules/markdown-link-check/index.js:129:13

As a user, I would like to know what line in the source it was failing on.

lyricnz commented 1 year ago

Same error here.

lyricnz commented 1 year ago

I modified .../node_modules/markdown-link-check/node_modules/link-check/lib/proto/http.js to print out URLs just before it hit the error at this is what it showed

❯ markdown-link-check -p -v README.md

FILE: README.md
https://lukeprior.github.io/nbn-upgrade-map/
https://data.gov.au/dataset/ds-dga-19432f89-dc3a-4ef3-b943-5326ef1dbecc/details
Checking... [==                       ] 7%https://github.com/minus34/gnaf-loader
Checking... [====                     ] 15%https://minus34.com/opendata/georabble-intro-to-gnaf.pdf
Checking... [======                   ] 23%https://www.nbnco.com.au/residential/upgrades/more-fibre
Checking... [========                 ] 30%https://geojson.org/
Checking... [==========               ] 38%https://geojson.io/
Checking... [============             ] 46%https://img.shields.io/badge/dynamic/json?label=Suburb%20Progress%20vs%20Listed&query=%24.suburbs.listed.TOTAL.percent&url=https%3A%2F%2Fraw.githubusercontent.com%2FLukePrior%2Fnbn-upgrade-map%2Fmain%2Fresults%2Fprogress.json&suffix=%
/Users/simonroberts/.asdf/installs/nodejs/14.20.0/lib/node_modules/markdown-link-check/node_modules/link-check/lib/proto/http.js:41
        const url = encodeURI(decodeURIComponent(new URL(link, opts.baseUrl).toString()));

In this case, the error is caused by a bare '%' sign which should be %25 for a percent sign.

lyricnz commented 1 year ago

FWIW what I changed was (crudely) adding the console.log() line immediately before the line that got the error:

        console.log(link)
        const url = encodeURI(decodeURIComponent(new URL(link, opts.baseUrl).toString()));