T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/lavocat.ca/public_html/node_modules/htmlparser2/src/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/lavocat.ca/public_html/node_modules/htmlparser2/src/WritableStream.spec.ts
import { createReadStream } from "node:fs";
import * as fs from "node:fs/promises";
import * as stream from "node:stream";
import { describe, it, expect, vi } from "vitest";
import type { Handler, ParserOptions } from "./Parser.js";
import { WritableStream } from "./WritableStream.js";
import * as helper from "./__fixtures__/testHelper.js";

describe("WritableStream", () => {
    it("should decode fragmented unicode characters", () => {
        const ontext = vi.fn();
        const stream = new WritableStream({ ontext });

        stream.write(Buffer.from([0xe2, 0x82]));
        stream.write(Buffer.from([0xac]));
        stream.write("");
        stream.end();

        expect(ontext).toHaveBeenCalledWith("€");
    });

    it("Basic html", () => testStream("Basic.html"));
    it("Attributes", () => testStream("Attributes.html"));
    it("SVG", () => testStream("Svg.html"));
    it("RSS feed", () => testStream("RSS_Example.xml", { xmlMode: true }));
    it("Atom feed", () => testStream("Atom_Example.xml", { xmlMode: true }));
    it("RDF feed", () => testStream("RDF_Example.xml", { xmlMode: true }));
});

function getPromiseEventCollector(): [
    handler: Partial<Handler>,
    promise: Promise<unknown>,
] {
    let handler: Partial<Handler> | undefined;
    const promise = new Promise<unknown>((resolve, reject) => {
        handler = helper.getEventCollector((error, events) => {
            if (error) {
                reject(error);
            } else {
                resolve(events);
            }
        });
    });

    return [handler!, promise];
}

// TODO[engine:node@>=16]: Use promise version of `stream.finished` instead.
function finished(input: Parameters<typeof stream.finished>[0]): Promise<void> {
    return new Promise((resolve, reject) => {
        stream.finished(input, (error) => (error ? reject(error) : resolve()));
    });
}

async function testStream(
    file: string,
    options?: ParserOptions,
): Promise<void> {
    const filePath = new URL(`__fixtures__/Documents/${file}`, import.meta.url);

    const [streamHandler, eventsPromise] = getPromiseEventCollector();

    const fsStream = createReadStream(filePath).pipe(
        new WritableStream(streamHandler, options),
    );

    await finished(fsStream);

    const events = await eventsPromise;

    expect(events).toMatchSnapshot();

    const [singlePassHandler, singlePassPromise] = getPromiseEventCollector();

    const singlePassStream = new WritableStream(singlePassHandler, options).end(
        await fs.readFile(filePath),
    );

    await finished(singlePassStream);

    expect(await singlePassPromise).toStrictEqual(events);
}

CasperSecurity Mini