kwhitley / itty-router-extras

An assortment of delicious extras for the calorie-light itty-router.
MIT License
84 stars 12 forks source link

Fix cookie accumulator #6

Closed rubnogueira closed 3 years ago

rubnogueira commented 3 years ago

Middleware withCookies doesn't work as expected when an cookie have a empty value.

const test = 'variable1=; variable2=abc';

// Original
test.split(/;\s*/).map(pair => pair.split('=')).reduce((acc, [key, value]) => (acc = {...acc, [key]: value}, {})
// Output: ""

// Fixed
test.split(/;\s*/).map(pair => pair.split('=')).reduce((acc, [key, value]) => (acc = {...acc, [key]: value}), {})
// Output: {variable1: "", variable2: "abc"}
rubnogueira commented 3 years ago

I just changed to a non ES6 solution, since Terser module gives an error while building.

kwhitley commented 3 years ago

Cool, one last whitespace fix then I'll merge! 👍 🥳

FYI, terser is giving me trouble as well and has prevented a pretty heavy release from going out... this fix will hopefully be released to NPM today, but currently I'm testing releases on itty-router-extras@next until that's sorted.

rubnogueira commented 3 years ago

That whiteline was added by ESLint --fix (failed in my second commit). Could you please check it?