Skip to content

Trailing slash added to urls in href when using linkedom #980

Open

Description

@richardklapac

Using standalone readability, version 0.6.0. Using the following minimal example:

<!DOCTYPE HTML">
<html>
<body>
<a href="/api/browser/proxy?url=https%3A%2F%2Fwww.debian.org%2Fsecurity%2Ffaq">https://www.debian.org/security/faq</a>
</body>
</html>

The string is parsed into a document using linkedom version 0.18.12. Inspecting the Node objects show the href as expected, without a slash.

Creating a new readability object and using the parse method however, generates an object with the href url having a newly added trailing slash. In this example, such a change leads to a 404 not found exception.

Activity

  1. gijsk commented on Sep 24, 2025

    @gijsk
    Contributor

    @richardklapac Does the same issue occur when using jsdom? I cannot reproduce when using jsdom, so I suspect this is a linkedom bug. If it's straightforward enough, I would take a patch that avoids this somehow, but to do that we'd need to know what exactly linkedom is doing and where readability is tripping up.

    generates an object with the href url having a newly added trailing slash

    To be clear, you're saying that the output in this case has a element's href manipulated?

  2. richardklapac commented on Sep 26, 2025

    @richardklapac
    Author

    I can't use jsdom at the moment, as the project is not in Node. If we can't pinpoint the linkedom/readability cause, I'll try to reproduce in a Node environment with jsdom as well. In the meantime:

    Yes, it seems that the a element's href is manipulated.

    Here is my minimal code, using the example provided:

    const html = `<!DOCTYPE HTML">
    <html>
    <body>
    <a href="/api/browser/proxy?url=https%3A%2F%2Fwww.debian.org%2Fsecurity%2Ffaq">https://www.debian.org/security/faq</a>
    </body>
    </html>
    `
    console.log(html) // contains correct /faq without a trailing slash
    
    const parser = new DOMParser();
    const doc = parser.parseFromString(html, 'text/html');
    
    console.log(doc.getElementsByTagName("a")[0]) // contains correct /faq without a trailing slash
    
    console.log(new Readability(doc).parse()!.content) // contains incorrect /faq/ with a trailing slash

    First log output is the example HTML.

    Second log output, sorry for the screenshot, React Native devs had the bright idea to force all logs to go through chrome, not cli, and I have no idea how to copy the raw value:

    Image

    Third log output:

    <DIV class="page" id="readability-page-1">
    <a href="/api/browser/proxy?url=https%3A%2F%2Fwww.debian.org%2Fsecurity%2Ffaq%2F">https://www.debian.org/security/faq</a>
    </DIV>
    
  3. changed the title [-]Trailing slash added to urls in href[/-] [+]Trailing slash added to urls in href when using linkedom[/+] on Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions