Home > widget-integration > FilterValidationHelper > sanitizeFilterLabel
FilterValidationHelper.sanitizeFilterLabel() method
Sanitizes a filter label by removing or blocking malicious content.
Returns a safe string that can be displayed in the UI. Uses strict blocking approach - malicious content is replaced with placeholder rather than sanitized.
Signature:
sanitizeFilterLabel(label: unknown): string;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
label |
unknown |
The filter label to sanitize. Non-string values are considered invalid. |
Returns:
string
Sanitized label string, '[Invalid Label]' for non-strings, or '[Blocked Content]' for malicious input
Remarks
Security Strategy: - Invalid/non-string inputs return '[Invalid Label]' - Malicious content (detected by isBadSearchTerm) returns '[Blocked Content]' - Safe content is returned as-is (browser's textContent/setAttribute handles safely) - No attempt to "fix" malicious content - blocking is safer than sanitization
Override this method to customize sanitization behavior, blocked content messages, or add shop-specific label transformations.
Example 1
Basic usage:
const safeLabel = this.validationHelper.sanitizeFilterLabel(userLabel);
element.textContent = safeLabel; // Safe to display
Example 2
Extend to customize blocked messages:
window.boostWidgetIntegration.extend('FilterValidationHelper', (FilterValidationHelper) => {
return class extends FilterValidationHelper {
sanitizeFilterLabel(label) {
if (!label || typeof label !== 'string') {
return this.getLocalizedMessage('invalid');
}
if (this.isBadSearchTerm(label)) {
console.warn('Blocked malicious label:', label);
return this.getLocalizedMessage('blocked');
}
return label;
}
};
});