Skip to content

Commit 69f25c5

Browse files
authored
fix(ssr-cookie): add null check for regex exec() result in cookie
fix(ssr-cookie): add null check for regex exec() result in cookie ret…
2 parents 70c976d + aaf40cd commit 69f25c5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

projects/ngx-cookie-service-ssr/src/lib/ssr-cookie.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { inject, Injectable, PLATFORM_ID, REQUEST } from '@angular/core';
21
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
2+
import { inject, Injectable, PLATFORM_ID, REQUEST } from '@angular/core';
33

44
@Injectable({
55
providedIn: 'root',
@@ -72,8 +72,8 @@ export class SsrCookieService {
7272
if (this.check(name)) {
7373
name = encodeURIComponent(name);
7474
const regExp: RegExp = SsrCookieService.getCookieRegExp(name);
75-
const result: RegExpExecArray = regExp.exec(this.documentIsAccessible ? this.document.cookie : this.request?.headers.get('cookie'));
76-
return result[1] ? SsrCookieService.safeDecodeURIComponent(result[1]) : '';
75+
const result = regExp.exec(this.documentIsAccessible ? this.document.cookie : this.request?.headers.get('cookie'));
76+
return result && result[1] ? SsrCookieService.safeDecodeURIComponent(result[1]) : '';
7777
}
7878
return '';
7979
}

0 commit comments

Comments
 (0)