Skip to content

Commit 662a8a2

Browse files
committed
Update version and refactor cookie handling
Updated version in csproj to 1.0.2. Modified `setCookie` to remove `encodeURIComponent`. Refactored `getCookie` for simplicity. Updated `getAllCookies` to remove `decodeURIComponent`.
1 parent ae7db86 commit 662a8a2

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/ManuHub.Blazor.Wasm.BrowserStorage/ManuHub.Blazor.Wasm.BrowserStorage.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
1818
<Icon>icon.png</Icon>
1919
<PackageIcon>icon.png</PackageIcon>
20-
<Version>1.0.1</Version>
20+
<Version>1.0.2</Version>
2121
<IsPackable>true</IsPackable>
2222
</PropertyGroup>
2323

src/ManuHub.Blazor.Wasm.BrowserStorage/wwwroot/browserStorage.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
export function setCookie(name, value, days) {
44
const date = new Date();
55
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); // Convert days to milliseconds
6-
document.cookie = `${name}=${encodeURIComponent(value)};expires=${date.toUTCString()};path=/`;
6+
document.cookie = `${name}=${value};expires=${date.toUTCString()};path=/`;
77
}
88

99
export function getCookie(name) {
10-
const cookies = document.cookie.split('; ');
11-
for (const cookie of cookies) {
12-
const [key, val] = cookie.split('=');
13-
if (key === name) return decodeURIComponent(val);
14-
}
10+
const value = `; ${document.cookie}`;
11+
const parts = value.split(`; ${name}=`);
12+
if (parts.length === 2) return parts.pop().split(';').shift();
1513
return null;
1614
}
1715

@@ -24,7 +22,7 @@ export function getAllCookies() {
2422
const result = {};
2523
for (const cookie of cookies) {
2624
const [key, val] = cookie.split('=');
27-
result[key] = decodeURIComponent(val);
25+
result[key] = val;
2826
}
2927
return result;
3028
}

0 commit comments

Comments
 (0)