From 79018dfeea77ebc4d90499a1f4a48e62f3ece62a Mon Sep 17 00:00:00 2001 From: Doug Martin Date: Tue, 1 Oct 2024 08:35:29 -0400 Subject: [PATCH] feat: Add "smart" quote matching [PT-188319600] --- src/stores/target_store.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/stores/target_store.ts b/src/stores/target_store.ts index 91290c9..fa7ee16 100644 --- a/src/stores/target_store.ts +++ b/src/stores/target_store.ts @@ -210,12 +210,27 @@ export class TargetStore { // note: the multiple slash escaping is due to all the layers between this code and the CODAP formula evaluator const escapedText = text .replace(/[.*+?^${}()|[\]\\]/g, '\\\\\\\\$&') // escape regex modifiers - .replace(/\s+/g, '\\\\\\\\s+'); // allow multiple spaces between words + .replace(/\s+/g, '\\\\\\\\s+') // allow multiple spaces between words + .replace(/['"“”‘’]/g, (match) => { // allow both regular and smart quotes to match each other + switch (match) { + case '"': + case '“': + case '”': + return `["“”]`; + case "'": + case '‘': + case '’': + return `['‘’]`; + default: + return match; + } + }); // don't add word boundaries when the user input starts/ends with non-word characters, like ! or , as that would fail matching const wordBoundary = `\\\\\\\\b`; const maybeStartingWordBoundary = /^\w/.test(text) ? wordBoundary : ''; const maybeEndingWordBoundary = /\w$/.test(text) ? wordBoundary : ''; const tParamString = `${tTargetAttr},"${tBegins}${maybeStartingWordBoundary}${escapedText}${maybeEndingWordBoundary}${tEnds}"`; + console.log("tParamString", tParamString); let tResult = ''; switch (option) {//['contain', 'not contain', 'start with', 'end with'] case featureDescriptors.containsOptions[0]: // contain