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

HTML parsing error with new line character #1678

Closed
Spixmaster opened this issue Jan 8, 2025 · 1 comment
Closed

HTML parsing error with new line character #1678

Spixmaster opened this issue Jan 8, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@Spixmaster
Copy link

Spixmaster commented Jan 8, 2025

Version: v16.5.2

The following test should pass but does not.

import {expect, test} from "bun:test";
import {Window} from "happy-dom";

test("showcase", (): undefined =>
{
    const window: Window = new Window();
    //@ts-expect-error
    global.window = window;
    //@ts-expect-error
    global.document = window.document;
    localStorage.clear();
    document.body.innerHTML = `            <div>
                <button class="btn btn-secondary comment_reply" data-id="{{id}}" type=
"button">{{message_gui_reply}}</button> <button class="btn btn-secondary comment_collapse
                 visually-hidden" type="button">{{message_gui_replies}}</button>
            </div>`;

    console.log(document.body.outerHTML);

    const tmp: Element | null = document.querySelector("div > .comment_collapse");
    expect(tmp).not.toBeNull();
});

Output:

tests/src-web/typescript/comment.test.ts:
<body>            <div>
                <button class="btn btn-secondary comment_reply" data-id="{{id}}" type="button">{{message_gui_reply}}</button> <button class="btn btn-secondary comment_collapse&#xA;                 visually-hidden" type="button">{{message_gui_replies}}</button>
            </div></body>
19 |             </div>`;
20 |
21 |     console.log(document.body.outerHTML);
22 |
23 |     const tmp: Element | null = document.querySelector("div > .comment_collapse");
24 |     expect(tmp).not.toBeNull();
                         ^
error: expect(received).not.toBeNull()

Received: null

      at /home/matheus/programmieren/c++/argo/tests/src-web/typescript/comment.test.ts:24:21
✗ showcase [12.20ms]

The error is obviously that the class which is followed by a line break is targeted but is modified to comment_collapse&#xA; during parsing.

@Spixmaster Spixmaster added the bug Something isn't working label Jan 8, 2025
@capricorn86 capricorn86 self-assigned this Jan 8, 2025
capricorn86 added a commit that referenced this issue Jan 8, 2025
…s in HTML (#1680)

* chore: [#1661] Adds unit test for testing bubbling of events

* fix: [#1661] Fixes problem with encoding and decoding attribute values in HTML

* chore: [#1678] Fixes problem with query selector
@capricorn86
Copy link
Owner

capricorn86 commented Jan 8, 2025

Thank you for reporting @Spixmaster! 🙂

There where two issues that caused the problem:

This has been fixed now in v16.5.3

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

When branches are created from issues, their pull requests are automatically linked.

2 participants