Skip to content

Commit e39931b

Browse files
fix: added sanitized function to fix the type error
1 parent d9c17ea commit e39931b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/frontend/wwwroot/app.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,31 @@
110110

111111
const fetchTasksIfNeeded = async () => {
112112
const taskStore = JSON.parse(sessionStorage.getItem('task'));
113+
114+
const sanitizeHeaderValue = (value) => {
115+
// Ensure the value is a valid UTF-8 string and URL-encode non-ASCII characters
116+
return encodeURIComponent(value);
117+
};
118+
119+
const sanitizeHeaders = (headers) => {
120+
const sanitizedHeaders = {};
121+
for (const key in headers) {
122+
if (headers.hasOwnProperty(key)) {
123+
const sanitizedKey = sanitizeHeaderValue(key); // Sanitize the key
124+
const sanitizedValue = sanitizeHeaderValue(headers[key]); // Sanitize the value
125+
sanitizedHeaders[sanitizedKey] = sanitizedValue;
126+
}
127+
}
128+
return sanitizedHeaders;
129+
};
130+
113131
window.headers
114132
.then(headers => {
133+
const sanitized = sanitizeHeaders(headers);
134+
console.log("Sanitized Headers:", sanitized);
115135
fetch(apiEndpoint + '/plans', {
116136
method: 'GET',
117-
headers: headers,
137+
headers: sanitized,
118138
})
119139
.then(response => response.json())
120140
.then(data => {

0 commit comments

Comments
 (0)