From 42abe667f78dff0c967c410d0bab2542e28cb1f0 Mon Sep 17 00:00:00 2001 From: Steve Jones Date: Fri, 29 May 2026 00:26:40 -0400 Subject: [PATCH] Use Unicode-aware regex in ambiguous text check to support non-Latin languages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes detection of translated ambiguous phrases (e.g. Danish "Læs mere") by replacing the ASCII-only /[^a-z]+/g regex with the Unicode-aware /[^\p{L}]+/gu variant. Also normalizes the phrases array on both sides of the comparison so translator punctuation variations don't cause missed matches. Closes #84 Co-Authored-By: Claude Sonnet 4.6 --- src/pageScanner/checks/has-ambiguous-text.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pageScanner/checks/has-ambiguous-text.js b/src/pageScanner/checks/has-ambiguous-text.js index 828921372..4f122a098 100644 --- a/src/pageScanner/checks/has-ambiguous-text.js +++ b/src/pageScanner/checks/has-ambiguous-text.js @@ -23,12 +23,16 @@ const ambiguousPhrases = [ __( 'opens a new window', 'accessibility-checker' ), ]; +const normalizedPhrases = ambiguousPhrases.map( + ( p ) => p.toLowerCase().replace( /[^\p{L}]+/gu, ' ' ).trim() +); + const checkAmbiguousPhrase = ( text ) => { if ( ! text ) { return false; } - text = text.toLowerCase().replace( /[^a-z]+/g, ' ' ).trim(); - return ambiguousPhrases.includes( text ); + text = text.toLowerCase().replace( /[^\p{L}]+/gu, ' ' ).trim(); + return normalizedPhrases.includes( text ); }; export default {