MCPcopy Index your code
hub / github.com/mozilla/source-map / buildSafeBase

Function buildSafeBase

lib/util.js:213–234  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

211}
212
213function buildSafeBase(str) {
214 const maxDotParts = str.split("..").length - 1;
215
216 // If we used a segment that also existed in `str`, then we would be unable
217 // to compute relative paths. For example, if `segment` were just "a":
218 //
219 // const url = "../../a/"
220 // const base = buildSafeBase(url); // http://host/a/a/
221 // const joined = "http://host/a/";
222 // const result = relative(base, joined);
223 //
224 // Expected: "../../a/";
225 // Actual: "a/"
226 //
227 const segment = buildUniqueSegment("p", str);
228
229 let base = `${PROTOCOL_AND_HOST}/`;
230 for (let i = 0; i < maxDotParts; i++) {
231 base += `${segment}/`;
232 }
233 return base;
234}
235
236const ABSOLUTE_SCHEME = /^[A-Za-z0-9\+\-\.]+:/;
237function getURLType(url) {

Callers 3

createSafeHandlerFunction · 0.85
joinFunction · 0.85
relativeIfPossibleFunction · 0.85

Calls 1

buildUniqueSegmentFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…