fix: String.split(str, n) stops after n separator (#10408)

This commit is contained in:
Victor Berchet
2016-08-01 11:33:35 -07:00
committed by GitHub
parent e73d0511cf
commit 13c8211065
8 changed files with 49 additions and 35 deletions

View File

@ -443,13 +443,14 @@ function relativePath(url: any /** TODO #9100 */): string {
'/' + urlParsingNode.pathname;
}
export function parseCookieValue(cookie: string, name: string): string {
export function parseCookieValue(cookieStr: string, name: string): string {
name = encodeURIComponent(name);
let cookies = cookie.split(';');
for (let cookie of cookies) {
let [key, value] = cookie.split('=', 2);
if (key.trim() === name) {
return decodeURIComponent(value);
for (const cookie of cookieStr.split(';')) {
const eqIndex = cookie.indexOf('=');
const [cookieName, cookieValue]: string[] =
eqIndex == -1 ? [cookie, ''] : [cookie.slice(0, eqIndex), cookie.slice(eqIndex + 1)];
if (cookieName.trim() === name) {
return decodeURIComponent(cookieValue);
}
}
return null;