From 4812e7cc6c446ca9ec25f64d687d83bde99b5316 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Thu, 30 Jan 2025 16:21:53 -0500 Subject: [PATCH] chore: add back escapeRegExp helper function for regex special character handling --- api/server/utils/handleText.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/api/server/utils/handleText.js b/api/server/utils/handleText.js index 6cef72385bb..e46584c805b 100644 --- a/api/server/utils/handleText.js +++ b/api/server/utils/handleText.js @@ -13,6 +13,14 @@ const { Providers } = require('@librechat/agents'); const partialRight = require('lodash/partialRight'); const { sendMessage } = require('./streamResponse'); +/** Helper function to escape special characters in regex + * @param {string} string - The string to escape. + * @returns {string} The escaped string. + */ +function escapeRegExp(string) { + return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); +} + const addSpaceIfNeeded = (text) => (text.length > 0 && !text.endsWith(' ') ? text + ' ' : text); const base = { message: true, initial: true }; @@ -251,6 +259,7 @@ module.exports = { isEnabled, handleText, formatSteps, + escapeRegExp, formatAction, isUserProvided, generateConfig,