}// if a url ENDs in . or .., then it must get a trailing slash.
// however, if it ends in anything else non-slashy,
// then it must NOT get a trailing slash.
varlast=srcPath.slice(-1)[0];
varhasTrailingSlash=(result.host||relative.host||srcPath.length>1)&&(last==='.'||last==='..')||last==='';// strip single dots, resolve double dots to parent dir
// if the path tries to go above the root, `up` ends up > 0
varup=0;
for(vari=srcPath.length;i>=0;i--){
last=srcPath[i];
if(last==='.'){
srcPath.splice(i,1);
}elseif(last==='..'){
srcPath.splice(i,1);
up++;
}elseif(up){
srcPath.splice(i,1);
up--;
}
}// if the path is allowed to go above the root, restore leading ..s