Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate all relative attributes using the base URL #1135

Closed
asportnoy opened this issue Oct 16, 2023 · 1 comment · Fixed by #1305
Closed

Calculate all relative attributes using the base URL #1135

asportnoy opened this issue Oct 16, 2023 · 1 comment · Fixed by #1305
Assignees
Labels
bug Something isn't working

Comments

@asportnoy
Copy link

asportnoy commented Oct 16, 2023

Describe the bug
Certain URL attributes currently do not currently handle calculating the full URL from the relative URL. Links (<a>) handle it, but all other attributes do not.

To Reproduce
Demo: https://runkit.com/embed/3ysykfxe8h47

const { Window } = require('happy-dom');

const { document } = new Window({
    url: 'https://example.com',
    settings: {
        disableJavaScriptFileLoading: true,
        disableCSSFileLoading: true,
    },
});

document.body.innerHTML = `
    <link rel="stylesheet" href="/test.css" />
    <img src="/test.png" alt="Test" />
    <form action="/test" />
    <a href="/test">Test</test>
    <script src="/test.js"></script>
`;

console.log(document.querySelector('link').href); // ❌ "/test.css"
console.log(document.querySelector('img').src); // ❌ "/test.png"
console.log(document.querySelector('form').action); // ❌ "/test"
console.log(document.querySelector('a').href); // ✅ "https://example.com/test"
console.log(document.querySelector('script').src); // ❌ "/test.js"

Expected behavior
All of the attributes above should return the absolute URL to the resource, like the <a> tag currently does. This is the behavior in a real browser, and we can also see that JSDOM handles all these attributes.

Actual Behavior
Only the <a> tag has the proper attribute handling.

Device:

  • Lib: v12.9.1
  • NodeJS: v16.20.2
  • OS: macOS Sonoma
@asportnoy asportnoy added the bug Something isn't working label Oct 16, 2023
@capricorn86 capricorn86 self-assigned this Mar 13, 2024
capricorn86 added a commit that referenced this issue Mar 13, 2024
…on in HTMLLinkElement.href, HTMLImageElement.src and HTMLScriptElement.src
capricorn86 added a commit that referenced this issue Mar 13, 2024
…-attributes-using-the-base-url

fix: [#1135] Adds support for returning URL relative to window locati…
@capricorn86
Copy link
Owner

Thank you for reporting @asportnoy! 🙂

There is a fix in now:
https://github.com/capricorn86/happy-dom/releases/tag/v13.8.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants