fix: added sanitizeString util helper (#2209)

This commit is contained in:
Piyush Gupta
2024-03-09 12:17:37 +05:30
committed by GitHub
parent e8aad9f469
commit c6ff74f166
2 changed files with 8 additions and 2 deletions

View File

@@ -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();
};

View File

@@ -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);
};