mirror of
https://github.com/FoxxMD/context-mod.git
synced 2026-04-19 03:00:07 -04:00
fix(regex): Fix regex generation for simple subreddit strings
* Trim value before parsing * If not a valid regex string then when generating regex from simple string add qualifiers for beginning/end of string so any matches must be exact
This commit is contained in:
11
src/util.ts
11
src/util.ts
@@ -904,17 +904,18 @@ export interface StrongSubredditStateOptions {
|
||||
|
||||
export const toStrongSubredditState = (s: SubredditState, opts?: StrongSubredditStateOptions): StrongSubredditState => {
|
||||
const {defaultFlags, generateDescription = false} = opts || {};
|
||||
const {name: nameVal, stateDescription} = s;
|
||||
const {name: nameValRaw, stateDescription} = s;
|
||||
|
||||
let nameReg: RegExp | undefined;
|
||||
if (nameVal !== undefined) {
|
||||
if (!(nameVal instanceof RegExp)) {
|
||||
if (nameValRaw !== undefined) {
|
||||
if (!(nameValRaw instanceof RegExp)) {
|
||||
const nameVal = nameValRaw.trim();
|
||||
nameReg = parseStringToRegex(nameVal, defaultFlags);
|
||||
if (nameReg === undefined) {
|
||||
nameReg = new RegExp(parseSubredditName(nameVal), defaultFlags);
|
||||
nameReg = parseStringToRegex(`/^${parseSubredditName(nameVal)}$/`, defaultFlags);
|
||||
}
|
||||
} else {
|
||||
nameReg = nameVal;
|
||||
nameReg = nameValRaw;
|
||||
}
|
||||
}
|
||||
const strongState = {
|
||||
|
||||
Reference in New Issue
Block a user