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

Cookie cannot be parsed on server #616

Open
Ben555555 opened this issue Jan 13, 2023 · 1 comment
Open

Cookie cannot be parsed on server #616

Ben555555 opened this issue Jan 13, 2023 · 1 comment
Labels

Comments

@Ben555555
Copy link

Ben555555 commented Jan 13, 2023

I store two cookies in my application in the browser:
language.code=en-US
authentication=1

Now when I refresh the page and access the cookie in the server side, there are some issues retrieving the cookies by key.
When i use cookieService.get('authentication') then
1;language.code=de-CH
is returned.
When I use cookieService.get('language.code') nothing is returned.
This is weird, so I used cookieService.getAll() to get the whole dictionary, which looks like this:
{
'authentication': '1;language.code=de-CH'
}

So there seems to be something wrong how the cookie on the server side is stored. The first key contains a value which also contains all the other key-value-pairs after the first semicolon.

Do I have to parse the cookie in another way?

@Ben555555 Ben555555 added the bug label Jan 13, 2023
@Ben555555
Copy link
Author

Ben555555 commented Jan 13, 2023

I created a temporary workaround for reading the cookies on server side:

private getMap(): Map<string, string> {
    const map = new Map<string, string>();
    const all = this.cookieService.getAll();

    for (let key in all) {
      let value = all[key];
      let i = 0;

      for (let item of value.split(';')) {
        if (i === 0) {
          map.set(key, item);
        }
        else {
          const parts = item.split('=');
          const subKey = parts[0];
          const subValue = parts[1];

          map.set(subKey, subValue);
        }

        i++;
      }
    }

    return map;
  }

This will read the cookie dictionary which seems to contain the first cookie key only. The value of this cookie key contains all other key value pairs as well. It will add all the key value pairs to the map.

I hope there is a fix soon, since this is kind of an ugly workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant