diff --git a/.changeset/sharp-chefs-glow.md b/.changeset/sharp-chefs-glow.md new file mode 100644 index 0000000000..bd0d469744 --- /dev/null +++ b/.changeset/sharp-chefs-glow.md @@ -0,0 +1,5 @@ +--- +"@siteimprove/alfa-rules": patch +--- + +**Fixed:** A regression on R1 for `
]); + + t.deepEqual(await evaluate(R74, { document }), [inapplicable(R74)]); +}); + test("evaluate() is inapplicable to a paragraph that isn't visible", async (t) => { const document = h.document([
diff --git a/packages/alfa-rules/tsconfig.json b/packages/alfa-rules/tsconfig.json index 6a9e2a1e2d..df95209048 100644 --- a/packages/alfa-rules/tsconfig.json +++ b/packages/alfa-rules/tsconfig.json @@ -43,7 +43,6 @@ "src/common/predicate/is-aria-controls-optional.ts", "src/common/predicate/is-at-the-start.ts", "src/common/predicate/is-large-text.ts", - "src/common/predicate/is-whitespace.ts", "src/common/predicate/reference-same-resource.ts", "src/deprecated.ts", "src/experimental.ts", diff --git a/packages/alfa-string/src/string.ts b/packages/alfa-string/src/string.ts index 7c4ea3480d..631133c9f9 100644 --- a/packages/alfa-string/src/string.ts +++ b/packages/alfa-string/src/string.ts @@ -14,10 +14,24 @@ export namespace String { return input.replace(/^/gm, " "); } + /** + * Collapses adjacent whitespace into a single ASCII space + */ + export function flatten(input: string): string { + return input.replace(/\s+/g, " ") + } + /** * Trims, collapses adjacent whitespace into a single ASCII space, optionally lowercases (default: true). */ export function normalize(input: string, toLowerCase: boolean = true): string { - return toLowerCase ? input.trim().toLowerCase().replace(/\s+/g, " ") : input.trim().replace(/\s+/g, " "); + return flatten(toLowerCase ? input.toLowerCase() : input).trim(); + } + + /** + * Checks whether the input contains only whitespace + */ + export function isWhitespace(input: string, allowEmpty: boolean = true): boolean { + return (allowEmpty || input.length > 0) && input.trim() === "" } }