RocketChat/Rocket.Chat

View on GitHub
apps/meteor/app/lib/server/functions/validateNameChars.ts

Summary

Maintainability
A
30 mins
Test Coverage
export const validateNameChars = (name: string | undefined): boolean => {
    if (typeof name !== 'string') {
        return false;
    }

    const invalidChars = /[<>\\/]/;
    if (invalidChars.test(name)) {
        return false;
    }

    try {
        const decodedName = decodeURI(name);
        if (invalidChars.test(decodedName)) {
            return false;
        }
    } catch (err) {
        return false;
    }

    return true;
};