mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-12 02:00:28 +03:00
sanitize string before used in regex to prevent crash (#2219)
This commit is contained in:
parent
d8d4bce287
commit
9fe67da98b
4 changed files with 13 additions and 5 deletions
|
|
@ -5,6 +5,7 @@ import { BlockType } from './types';
|
|||
import { CustomElement } from './slate';
|
||||
import { parseBlockMD, parseInlineMD } from '../../plugins/markdown';
|
||||
import { findAndReplace } from '../../utils/findAndReplace';
|
||||
import { sanitizeForRegex } from '../../utils/regex';
|
||||
|
||||
export type OutputOptions = {
|
||||
allowTextFormatting?: boolean;
|
||||
|
|
@ -179,7 +180,7 @@ export const customHtmlEqualsPlainText = (customHtml: string, plain: string): bo
|
|||
export const trimCustomHtml = (customHtml: string) => customHtml.replace(/<br\/>$/g, '').trim();
|
||||
|
||||
export const trimCommand = (cmdName: string, str: string) => {
|
||||
const cmdRegX = new RegExp(`^(\\s+)?(\\/${cmdName})([^\\S\n]+)?`);
|
||||
const cmdRegX = new RegExp(`^(\\s+)?(\\/${sanitizeForRegex(cmdName)})([^\\S\n]+)?`);
|
||||
|
||||
const match = str.match(cmdRegX);
|
||||
if (!match) return str;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue