From 9d8c0332bec5e80899445d06b6dddf8e2e256646 Mon Sep 17 00:00:00 2001 From: nachtjasmin Date: Sun, 16 Jul 2023 11:20:55 +0200 Subject: [PATCH 1/2] Switch to a regex-only pronoun field matching --- src/libs/pronouns.js | 7 ++----- tests/extractPronouns.spec.js | 4 +++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libs/pronouns.js b/src/libs/pronouns.js index 3a548a7..78dad1f 100644 --- a/src/libs/pronouns.js +++ b/src/libs/pronouns.js @@ -1,6 +1,6 @@ import sanitizeHtml from "sanitize-html"; -const fieldMatchers = [/\bpro.*nouns?\b/i, "pronomen"]; +const fieldMatchers = [/\bpro.*nouns?\b/i, /\bpronomen\b/i]; const knownPronounUrls = [ /pronouns\.page\/:?([\w/@]+)/, /pronouns\.within\.lgbt\/([\w/]+)/, @@ -44,10 +44,7 @@ export async function extractFromStatus(status) { async function extractFromField(field) { let pronounsRaw; for (const matcher of fieldMatchers) { - if (typeof matcher === "string" && field.name.toLowerCase().includes(matcher)) { - pronounsRaw = field.value; - break; - } else if (field.name.match(matcher)) { + if (field.name.match(matcher)) { pronounsRaw = field.value; break; } diff --git a/tests/extractPronouns.spec.js b/tests/extractPronouns.spec.js index bc1babf..4a7ca7d 100644 --- a/tests/extractPronouns.spec.js +++ b/tests/extractPronouns.spec.js @@ -10,8 +10,10 @@ const validFields = [ "professional nouns", "pronomen", "Pronouns / Pronomen", + "Pronomen (DE)", + "Pronouns (EN)", ]; -const invalidFields = ["pronounciation"]; +const invalidFields = ["pronounciation", "pronomenverwaltung"]; for (const field of validFields) { extract(`${field} is extracted`, async () => { From 96c530c30f032e3f00a6f659ca02c353c3b0bf6a Mon Sep 17 00:00:00 2001 From: ItsVipra Date: Mon, 17 Jul 2023 12:18:31 +0200 Subject: [PATCH 2/2] add matcher for "(i) go(es) by" --- src/libs/pronouns.js | 2 +- tests/extractPronouns.spec.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/pronouns.js b/src/libs/pronouns.js index 78dad1f..dc85fa1 100644 --- a/src/libs/pronouns.js +++ b/src/libs/pronouns.js @@ -1,6 +1,6 @@ import sanitizeHtml from "sanitize-html"; -const fieldMatchers = [/\bpro.*nouns?\b/i, /\bpronomen\b/i]; +const fieldMatchers = [/\bpro.*nouns?\b/i, /\bpronomen\b/i, /(i )?go(es)? by/i]; const knownPronounUrls = [ /pronouns\.page\/:?([\w/@]+)/, /pronouns\.within\.lgbt\/([\w/]+)/, diff --git a/tests/extractPronouns.spec.js b/tests/extractPronouns.spec.js index 4a7ca7d..b4cd980 100644 --- a/tests/extractPronouns.spec.js +++ b/tests/extractPronouns.spec.js @@ -12,6 +12,8 @@ const validFields = [ "Pronouns / Pronomen", "Pronomen (DE)", "Pronouns (EN)", + "i go by", + "go by", ]; const invalidFields = ["pronounciation", "pronomenverwaltung"];