mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-16 10:31:00 -06:00
fix: added sanitizeString util helper (#2209)
This commit is contained in:
@@ -18,6 +18,7 @@ import {
|
||||
} from "@formbricks/types/responses";
|
||||
import { TSurvey, TSurveyQuestionType } from "@formbricks/types/surveys";
|
||||
|
||||
import { sanitizeString } from "../strings";
|
||||
import { getTodaysDateTimeFormatted } from "../time";
|
||||
import { evaluateCondition } from "../utils/evaluateLogic";
|
||||
|
||||
@@ -307,8 +308,8 @@ export const buildWhereClause = (filterCriteria?: TResponseFilterCriteria) => {
|
||||
};
|
||||
|
||||
export const getResponsesFileName = (surveyName: string, extension: string) => {
|
||||
// replacing / with : to avoid url issues
|
||||
surveyName = surveyName.replaceAll("/", ":");
|
||||
surveyName = sanitizeString(surveyName);
|
||||
|
||||
const formattedDateString = getTodaysDateTimeFormatted("-");
|
||||
return `export-${surveyName.split(" ").join("-")}-${formattedDateString}.${extension}`.toLocaleLowerCase();
|
||||
};
|
||||
|
||||
@@ -24,3 +24,8 @@ export const truncateMiddle = (str: string, length: number) => {
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
// write a function that takes a string and removes all characters that could cause issues with the url and truncates it to the specified length
|
||||
export const sanitizeString = (str: string, delimiter: string = "_", length: number = 255) => {
|
||||
return str.replace(/[^0-9a-zA-Z\-._]+/g, delimiter).substring(0, length);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user