fix(codegen): trim alt selectors to 80 chars (#31346)

Fixes https://github.com/microsoft/playwright/issues/31254
This commit is contained in:
Yury Semikhatsky 2024-06-17 16:32:22 -07:00 committed by GitHub
parent f3f708e01a
commit 5443b66636
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -528,7 +528,7 @@ function suitableTextAlternatives(text: string) {
const match = text.match(/^([\d.,]+)[^.,\w]/);
const leadingNumberLength = match ? match[1].length : 0;
if (leadingNumberLength) {
const alt = text.substring(leadingNumberLength).trimStart();
const alt = trimWordBoundary(text.substring(leadingNumberLength).trimStart(), 80);
result.push({ text: alt, scoreBouns: alt.length <= 30 ? 2 : 1 });
}
}
@ -537,7 +537,7 @@ function suitableTextAlternatives(text: string) {
const match = text.match(/[^.,\w]([\d.,]+)$/);
const trailingNumberLength = match ? match[1].length : 0;
if (trailingNumberLength) {
const alt = text.substring(0, text.length - trailingNumberLength).trimEnd();
const alt = trimWordBoundary(text.substring(0, text.length - trailingNumberLength).trimEnd(), 80);
result.push({ text: alt, scoreBouns: alt.length <= 30 ? 2 : 1 });
}
}