Skip to content

Commit

Permalink
chore: add back escapeRegExp helper function for regex special charac…
Browse files Browse the repository at this point in the history
…ter handling
  • Loading branch information
danny-avila committed Jan 30, 2025
1 parent 7632683 commit 4812e7c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api/server/utils/handleText.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -251,6 +259,7 @@ module.exports = {
isEnabled,
handleText,
formatSteps,
escapeRegExp,
formatAction,
isUserProvided,
generateConfig,
Expand Down

0 comments on commit 4812e7c

Please sign in to comment.