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

@ -10,14 +10,14 @@ import {ListWrapper, Map, isListLikeIterable} from '../src/facade/collection';
import {isPresent} from '../src/facade/lang';
function paramParser(rawParams: string = ''): Map<string, string[]> {
var map = new Map<string, string[]>();
const map = new Map<string, string[]>();
if (rawParams.length > 0) {
var params: string[] = rawParams.split('&');
const params: string[] = rawParams.split('&');
params.forEach((param: string) => {
var split: string[] = param.split('=', 2);
var key = split[0];
var val = split[1];
var list = isPresent(map.get(key)) ? map.get(key) : [];
const eqIdx = param.indexOf('=');
const [key, val]: string[] =
eqIdx == -1 ? [param, ''] : [param.slice(0, eqIdx), param.slice(eqIdx + 1)];
const list = map.get(key) || [];
list.push(val);
map.set(key, list);
});