Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Added sanitized function to fix the type error #32

Open
wants to merge 2 commits into
base: hotfix
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/frontend/wwwroot/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,31 @@

const fetchTasksIfNeeded = async () => {
const taskStore = JSON.parse(sessionStorage.getItem('task'));

const sanitizeHeaderValue = (value) => {
// Ensure the value is a valid UTF-8 string and URL-encode non-ASCII characters
return encodeURIComponent(value);
};

const sanitizeHeaders = (headers) => {
const sanitizedHeaders = {};
for (const key in headers) {
if (headers.hasOwnProperty(key)) {
const sanitizedKey = sanitizeHeaderValue(key); // Sanitize the key
const sanitizedValue = sanitizeHeaderValue(headers[key]); // Sanitize the value
sanitizedHeaders[sanitizedKey] = sanitizedValue;
}
}
return sanitizedHeaders;
};

window.headers
.then(headers => {
const sanitized = sanitizeHeaders(headers);
console.log("Sanitized Headers:", sanitized);
fetch(apiEndpoint + '/plans', {
method: 'GET',
headers: headers,
headers: sanitized,
})
.then(response => response.json())
.then(data => {
Expand Down
Loading