Software: Apache. PHP/8.1.30 uname -a: Linux server1.tuhinhossain.com 5.15.0-163-generic #173-Ubuntu SMP Tue Oct 14 17:51:00 UTC uid=1002(picotech) gid=1003(picotech) groups=1003(picotech),0(root) Safe-mode: OFF (not secure) /home/picotech/domains/rentals.picotech.app/public_html/server/utils/ drwxr-xr-x | |
| Viewing file: Select action/file-type: /**
* Strip all HTML tags from input
* @param {string} input - Input string that may contain HTML
* @returns {string} - Clean string without HTML tags
*/
export const stripHtmlTags = (input) => {
if (!input || typeof input !== 'string') return input;
// Remove all HTML tags
let cleaned = input.replace(/<[^>]*>/g, '');
// Decode HTML entities
cleaned = cleaned
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, "'")
.replace(///g, '/');
// Remove any remaining script content
cleaned = cleaned.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
return cleaned.trim();
};
/**
* Validate that input doesn't contain HTML tags
* @param {string} input - Input to validate
* @returns {boolean} - True if valid (no HTML), false otherwise
*/
export const isValidNoHtml = (input) => {
if (!input || typeof input !== 'string') return true;
// Check for HTML tags
const htmlTagPattern = /<[^>]*>/;
return !htmlTagPattern.test(input);
};
/**
* Sanitize object by stripping HTML from all string values
* @param {object} obj - Object to sanitize
* @returns {object} - Sanitized object
*/
export const stripHtmlFromObject = (obj) => {
if (!obj || typeof obj !== 'object') return obj;
const sanitized = { ...obj };
for (const key in sanitized) {
if (typeof sanitized[key] === 'string') {
sanitized[key] = stripHtmlTags(sanitized[key]);
} else if (typeof sanitized[key] === 'object' && sanitized[key] !== null) {
sanitized[key] = stripHtmlFromObject(sanitized[key]);
}
}
return sanitized;
};
/**
* Express middleware to strip HTML tags from request body
*/
export const stripHtmlMiddleware = (req, res, next) => {
if (req.body && typeof req.body === 'object') {
req.body = stripHtmlFromObject(req.body);
}
if (req.query && typeof req.query === 'object') {
req.query = stripHtmlFromObject(req.query);
}
next();
};
export default {
stripHtmlTags,
isValidNoHtml,
stripHtmlFromObject,
stripHtmlMiddleware
};
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0043 ]-- |