danmactough / node-feedparser

Robust RSS, Atom, and RDF feed parsing in Node.js
Other
1.97k stars 192 forks source link

Node 20.11.1 emits deprecation warning DEP0170 #295

Open gromnitsky opened 7 months ago

gromnitsky commented 7 months ago

I stumbled upon this while parsing a mastodon feed (I saved the example here). A minimal variant of an unfourtunate feed boils down to

<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <link rel="self" href="http://example.com" />
  <entry>
    <link href="tag:mefi.social,2024-01-26:objectId=20368395" />
  </entry>
</feed>

If I parse such xml with feedparser 2.2.1

import FeedParser from 'feedparser'
import {pipeline} from 'stream/promises'
import {createReadStream} from 'fs'

let feedparser = new FeedParser()
await pipeline(createReadStream(process.argv[2]), feedparser)

I get

$ node --throw-deprecation DEP0170.js lol.xml
node:internal/process/warning:185
        throw warning;
        ^

DeprecationWarning: The URL tag:mefi.social,2024-01-26:objectId=20368395 is invalid. Future versions of Node.js will throw an error.
    at getHostname (node:url:516:17)
    at Url.parse (node:url:384:14)
    at urlParse (node:url:141:13)
    at Url.resolve (node:url:722:29)
    at Object.urlResolve [as resolve] (node:url:718:40)
    at /mnt/hdd3/Downloads/DEP0170/node_modules/feedparser/lib/utils.js:148:46
    at Array.forEach (<anonymous>)
    at /mnt/hdd3/Downloads/DEP0170/node_modules/feedparser/lib/utils.js:145:19
    at Array.forEach (<anonymous>)
    at resolveLevel (/mnt/hdd3/Downloads/DEP0170/node_modules/feedparser/lib/utils.js:120:9) {
  code: 'DEP0170'
}
danmactough commented 7 months ago

Thanks for the report @gromnitsky

Looks like the solution in https://github.com/npm/npm-package-arg/pull/141 should work for us, too.