Skip to content

Commit

Permalink
fix(ssr-cookie): add null check for regex exec() result in cookie
Browse files Browse the repository at this point in the history
fix(ssr-cookie): add null check for regex exec() result in cookie ret…
  • Loading branch information
pavankjadda authored Feb 21, 2025
2 parents 70c976d + aaf40cd commit 69f25c5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions projects/ngx-cookie-service-ssr/src/lib/ssr-cookie.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inject, Injectable, PLATFORM_ID, REQUEST } from '@angular/core';
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
import { inject, Injectable, PLATFORM_ID, REQUEST } from '@angular/core';

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -72,8 +72,8 @@ export class SsrCookieService {
if (this.check(name)) {
name = encodeURIComponent(name);
const regExp: RegExp = SsrCookieService.getCookieRegExp(name);
const result: RegExpExecArray = regExp.exec(this.documentIsAccessible ? this.document.cookie : this.request?.headers.get('cookie'));
return result[1] ? SsrCookieService.safeDecodeURIComponent(result[1]) : '';
const result = regExp.exec(this.documentIsAccessible ? this.document.cookie : this.request?.headers.get('cookie'));
return result && result[1] ? SsrCookieService.safeDecodeURIComponent(result[1]) : '';
}
return '';
}
Expand Down

0 comments on commit 69f25c5

Please sign in to comment.