urlGlob.ts ×14

Frontier kind: Code frontier

unlabeled · c_f84cef1ad8a8

35 tests · 3587 LOC · 19 files · introduces 0 tests · 69 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
14 ranges69 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
540 ranges3587 lines · 19 files · Browse complete extent
All tests (intent)
35 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 69 introduced LOC across 14 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/url/common/urlGlob.ts 69 introduced LOC · 14 ranges

Open complete file

11 * @returns URI - The normalized URI object.
12 */
13 > function normalizeURL(url: string | URI): URI { urlGlob.ts
14 > const uri = typeof url === 'string' ? URI.parse(url) : url;
15 > return uri.with({
16 > // Remove trailing slashes
17 > path: uri.path.replace(/\/+$/, ''),
18 > // Remove query and fragment
19 > query: null,
20 > fragment: null,
21 > });
22 > }
23
24 /**
30 */
31 export function testUrlMatchesGlob(uri: string | URI, globUrl: string): boolean {
32 > const normalizedUrl = normalizeURL(uri); urlGlob.ts
33 > let normalizedGlobUrl: URI;
34 >
35 > const globHasScheme = /^[^./:]*:\/\//.test(globUrl);
36 > // if the glob does not have a scheme we assume the scheme is http or https
37 > // so if the url doesn't have a scheme of http or https we return false
38 > if (!globHasScheme) {
39 if (normalizedUrl.scheme !== 'http' && normalizedUrl.scheme !== 'https') {
40 return false;
41 }
42 normalizedGlobUrl = normalizeURL(`${normalizedUrl.scheme}://${globUrl}`);
43 > } else { urlGlob.ts
44 normalizedGlobUrl = normalizeURL(globUrl);
45 }
46 > urlGlob.ts
47 > return (
48 > doMemoUrlMatch(normalizedUrl.scheme, normalizedGlobUrl.scheme) &&
49 // The authority is the only thing that should do port logic.
50 doMemoUrlMatch(normalizedUrl.authority, normalizedGlobUrl.authority, true) &&
53 normalizedGlobUrl.path === '/' ||
54 doMemoUrlMatch(normalizedUrl.path, normalizedGlobUrl.path)
55 > ) urlGlob.ts
56 > );
57 > }
58
59 /**
63 * @returns boolean - True if the URL part matches the glob URL part, false otherwise.
64 */
65 > function doMemoUrlMatch( urlGlob.ts
66 > normalizedUrlPart: string,
67 > normalizedGlobUrlPart: string,
68 > includePortLogic: boolean = false,
69 > ) {
70 > const memo = Array.from({ length: normalizedUrlPart.length + 1 }).map(() =>
71 > Array.from({ length: normalizedGlobUrlPart.length + 1 }).map(() => undefined),
72 > );
73 >
74 > return doUrlPartMatch(memo, includePortLogic, normalizedUrlPart, normalizedGlobUrlPart, 0, 0);
75 > }
76
77 /**
87 * @returns boolean - True if the URL part matches the glob URL part, false otherwise.
88 */
89 > function doUrlPartMatch( urlGlob.ts
90 > memo: (boolean | undefined)[][],
91 > includePortLogic: boolean,
92 > urlPart: string,
93 > globUrlPart: string,
94 > urlOffset: number,
95 > globUrlOffset: number
96 > ): boolean {
97 > if (memo[urlOffset]?.[globUrlOffset] !== undefined) {
98 return memo[urlOffset][globUrlOffset]!;
99 }
100 > urlGlob.ts
101 > const options = [];
102 >
103 > // We've reached the end of the url.
104 > if (urlOffset === urlPart.length) {
105 > // We're also at the end of the glob url as well so we have an exact match.
106 > if (globUrlOffset === globUrlPart.length) {
107 return true;
108 }
109
110 > if (includePortLogic && globUrlPart[globUrlOffset] + globUrlPart[globUrlOffset + 1] === ':*') { urlGlob.ts
111 // any port match. Consume a port if it exists otherwise nothing. Always consume the base.
112 return globUrlOffset + 2 === globUrlPart.length;
115 return false;
116 }
117 > urlGlob.ts
118 > // Some path remaining in url
119 > if (globUrlOffset === globUrlPart.length) {
120 const remaining = urlPart.slice(urlOffset);
121 return remaining[0] === '/';
122 }
123 > urlGlob.ts
124 > if (urlPart[urlOffset] === globUrlPart[globUrlOffset]) {
125 > // Exact match.
126 > options.push(doUrlPartMatch(memo, includePortLogic, urlPart, globUrlPart, urlOffset + 1, globUrlOffset + 1));
127 > }
128 >
129 > if (globUrlPart[globUrlOffset] + globUrlPart[globUrlOffset + 1] === '*.') {
130 // Any subdomain match. Either consume one thing that's not a / or : and don't advance base or consume nothing and do.
131 if (!['/', ':'].includes(urlPart[urlOffset])) {
137 }
138 }
139 > urlGlob.ts
140 > if (globUrlPart[globUrlOffset] === '*') {
141 // Any match. Either consume one thing and don't advance base or consume nothing and do.
142 if (urlOffset + 1 === urlPart.length) {
148 options.push(doUrlPartMatch(memo, includePortLogic, urlPart, globUrlPart, urlOffset, globUrlOffset + 1));
149 }
150 > urlGlob.ts
151 > if (includePortLogic && globUrlPart[globUrlOffset] + globUrlPart[globUrlOffset + 1] === ':*') {
152 // any port match. Consume a port if it exists otherwise nothing. Always consume the base.
153 if (urlPart[urlOffset] === ':') {
159 }
160 }
161 > urlGlob.ts
162 > return (memo[urlOffset][globUrlOffset] = options.some(a => a === true));
163 > }