MCPcopy Create free account
hub / github.com/ChromeDevTools/devtools-frontend / normalizePath

Function normalizePath

front_end/core/common/ParsedURL.ts:10–39  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

8 * http://tools.ietf.org/html/rfc3986#section-5.2.4
9 */
10export function normalizePath(path: string): string {
11 if (path.indexOf('..') === -1 && path.indexOf('.') === -1) {
12 return path;
13 }
14
15 // Remove leading slash (will be added back below) so we
16 // can handle all (including empty) segments consistently.
17 const segments = (path[0] === '/' ? path.substring(1) : path).split('/');
18 const normalizedSegments = [];
19 for (const segment of segments) {
20 if (segment === '.') {
21 continue;
22 } else if (segment === '..') {
23 normalizedSegments.pop();
24 } else {
25 normalizedSegments.push(segment);
26 }
27 }
28 let normalizedPath = normalizedSegments.join('/');
29 if (path[0] === '/' && normalizedPath) {
30 normalizedPath = '/' + normalizedPath;
31 }
32 if (normalizedPath[normalizedPath.length - 1] !== '/' &&
33 ((path[path.length - 1] === '/') || (segments[segments.length - 1] === '.') ||
34 (segments[segments.length - 1] === '..'))) {
35 normalizedPath = normalizedPath + '/';
36 }
37
38 return normalizedPath;
39}
40
41export function schemeIs(url: Platform.DevToolsPath.UrlString|URL, scheme: string): boolean {
42 try {

Callers 1

completeURLMethod · 0.85

Calls 6

indexOfMethod · 0.80
splitMethod · 0.80
substringMethod · 0.80
popMethod · 0.80
pushMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected