Skip to content

Commit

Permalink
fix(cookie): adds null check for regex exec() method
Browse files Browse the repository at this point in the history
fix(cookie): adds null check for regex exec() method
  • Loading branch information
pavankjadda authored Feb 21, 2025
2 parents ac9c5e3 + 964b361 commit 70c976d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions projects/ngx-cookie-service/src/lib/cookie.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// not use `DOCUMENT` injection and therefore doesn't work well with AoT production builds.
// Package: https://github.com/BCJTI/ng2-cookies

import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';

export type SameSite = 'Lax' | 'None' | 'Strict';

Expand Down Expand Up @@ -94,8 +94,8 @@ export class CookieService {
if (this.check(name)) {
name = encodeURIComponent(name);
const regExp: RegExp = CookieService.getCookieRegExp(name);
const result: RegExpExecArray = regExp.exec(this.document.cookie);
return result[1] ? CookieService.safeDecodeURIComponent(result[1]) : '';
const result = regExp.exec(this.document.cookie);
return result && result[1] ? CookieService.safeDecodeURIComponent(result[1]) : '';
} else {
return '';
}
Expand Down

0 comments on commit 70c976d

Please sign in to comment.