Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add "smart" quote matching [PT-188319600] #11

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/stores/target_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading