-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml-escape.js
More file actions
33 lines (28 loc) · 865 Bytes
/
Copy pathhtml-escape.js
File metadata and controls
33 lines (28 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Escape HTML special characters in a string
* @param {string} text - Text to escape
* @returns {string} - Escaped text
*/
export function escapeHtml(text) {
if (!text) return text;
// Replace HTML special characters with their entity equivalents
return text
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
/**
* Escape HTML in ride fields
* @param {Object} ride - Ride object
* @returns {Object} - Ride with escaped fields
*/
export function escapeRideHtml(ride) {
if (!ride) return ride;
const result = { ...ride };
// Only escape string fields that might contain HTML
if (result.title) result.title = escapeHtml(result.title);
if (result.meetingPoint) result.meetingPoint = escapeHtml(result.meetingPoint);
return result;
}