mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-05 15:49:15 +00:00
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
There apparently is a bit of a disconnect between the spec asking us to construct the pattern using code points and LibRegex not being able to swallow those. Whenever we had multi-byte code points in the pattern and tried to match that in unicode mode, we would fail. Change the parser to encode all non-ASCII code units. Fixes 2 test262 cases in `language/literals/regexp`.
99 lines
3.4 KiB
JavaScript
99 lines
3.4 KiB
JavaScript
describe("errors", () => {
|
|
test("invalid pattern", () => {
|
|
expect(() => {
|
|
RegExp("[");
|
|
}).toThrowWithMessage(
|
|
SyntaxError,
|
|
"RegExp compile error: Error during parsing of regular expression:"
|
|
);
|
|
});
|
|
|
|
test("invalid flag", () => {
|
|
expect(() => {
|
|
RegExp("", "x");
|
|
}).toThrowWithMessage(SyntaxError, "Invalid RegExp flag 'x'");
|
|
});
|
|
|
|
test("repeated flag", () => {
|
|
expect(() => {
|
|
RegExp("", "gg");
|
|
}).toThrowWithMessage(SyntaxError, "Repeated RegExp flag 'g'");
|
|
});
|
|
});
|
|
|
|
test("basic functionality", () => {
|
|
expect(RegExp().toString()).toBe("/(?:)/");
|
|
expect(RegExp(undefined).toString()).toBe("/(?:)/");
|
|
expect(RegExp("foo").toString()).toBe("/foo/");
|
|
expect(RegExp("foo", undefined).toString()).toBe("/foo/");
|
|
expect(RegExp("foo", "g").toString()).toBe("/foo/g");
|
|
expect(RegExp(undefined, "g").toString()).toBe("/(?:)/g");
|
|
});
|
|
|
|
test("regexp object as pattern parameter", () => {
|
|
expect(RegExp(/foo/).toString()).toBe("/foo/");
|
|
expect(RegExp(/foo/g).toString()).toBe("/foo/g");
|
|
expect(RegExp(/foo/g, "").toString()).toBe("/foo/");
|
|
expect(RegExp(/foo/g, "y").toString()).toBe("/foo/y");
|
|
|
|
var regex_like_object_without_flags = {
|
|
source: "foo",
|
|
[Symbol.match]: function () {},
|
|
};
|
|
expect(RegExp(regex_like_object_without_flags).toString()).toBe("/foo/");
|
|
expect(RegExp(regex_like_object_without_flags, "y").toString()).toBe("/foo/y");
|
|
|
|
var regex_like_object_with_flags = {
|
|
source: "foo",
|
|
flags: "g",
|
|
[Symbol.match]: function () {},
|
|
};
|
|
expect(RegExp(regex_like_object_with_flags).toString()).toBe("/foo/g");
|
|
expect(RegExp(regex_like_object_with_flags, "").toString()).toBe("/foo/");
|
|
expect(RegExp(regex_like_object_with_flags, "y").toString()).toBe("/foo/y");
|
|
});
|
|
|
|
test("regexp literals are re-useable", () => {
|
|
for (var i = 0; i < 2; ++i) {
|
|
const re = /test/;
|
|
expect(re.test("te")).toBeFalse();
|
|
expect(re.test("test")).toBeTrue();
|
|
}
|
|
});
|
|
|
|
test("Incorrectly escaped code units not converted to invalid patterns", () => {
|
|
const re = /[\⪾-\⫀]/;
|
|
expect(re.test("⫀")).toBeTrue();
|
|
expect(re.test("\\u2abe")).toBeFalse(); // ⫀ is \u2abe
|
|
});
|
|
|
|
test("regexp that always matches stops matching if it's past the end of the string instead of infinitely looping", () => {
|
|
const re = new RegExp("[\u200E]*", "gu");
|
|
expect("whf".match(re)).toEqual(["", "", "", ""]);
|
|
expect(re.lastIndex).toBe(0);
|
|
});
|
|
|
|
test("v flag should enable unicode mode", () => {
|
|
const re = new RegExp("a\\u{10FFFF}", "v");
|
|
expect(re.test("a\u{10FFFF}")).toBe(true);
|
|
});
|
|
|
|
test("parsing a large bytestring shouldn't crash", () => {
|
|
RegExp(new Uint8Array(0x40000));
|
|
});
|
|
|
|
test("Unicode non-ASCII matching", () => {
|
|
const cases = [
|
|
{ pattern: /é/u, match: "é", expected: ["é"] },
|
|
{ pattern: /é/, match: "é", expected: ["é"] },
|
|
{ pattern: /\u{61}/u, match: "a", expected: ["a"] },
|
|
{ pattern: /\u{61}/, match: "a", expected: null },
|
|
{ pattern: /😄/u, match: "😄", expected: ["😄"] },
|
|
{ pattern: /😄/u, match: "\ud83d", expected: null },
|
|
{ pattern: /😄/, match: "\ud83d", expected: null },
|
|
];
|
|
for (const test of cases) {
|
|
const result = test.match.match(test.pattern);
|
|
expect(result).toEqual(test.expected);
|
|
}
|
|
});
|