-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcompression.diff
More file actions
497 lines (470 loc) · 15 KB
/
Copy pathcompression.diff
File metadata and controls
497 lines (470 loc) · 15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
--- input/input.ts
+++ output/output.ts
@@ -58,20 +58,7 @@
function _referenceResolution(scheme: string, path: string): string {
// the slash-character is our 'default base' as we don't
- // support constructing URIs relative to other URIs. This
- // also means that we alter and potentially break paths.
- // see https://tools.ietf.org/html/rfc3986#section-5.1.4
- switch (scheme) {
- case 'https':
- case 'http':
- case 'file':
- if (!path) {
- path = _slash;
- } else if (path[0] !== _slash) {
- path = _slash + path;
- }
- break;
- }
+{ … 14 line(s) … ⟦tj:5464103aa9f50450b3236344d6db8e4e⟧ }
return path;
}
@@ -100,19 +87,9 @@
static isUri(thing: any): thing is URI {
if (thing instanceof URI) {
return true;
- }
- if (!thing) {
- return false;
- }
- return typeof (<URI>thing).authority === 'string'
- && typeof (<URI>thing).fragment === 'string'
- && typeof (<URI>thing).path === 'string'
- && typeof (<URI>thing).query === 'string'
- && typeof (<URI>thing).scheme === 'string'
- && typeof (<URI>thing).fsPath === 'string'
- && typeof (<URI>thing).with === 'function'
+ { … 11 line(s) … ⟦tj:1c5429c9a1b270b0e13830f228d49723⟧ }
&& typeof (<URI>thing).toString === 'function';
- }
+}
/**
* scheme is the 'http' part of 'http://www.example.com/some/path?query#fragment'.
@@ -214,47 +191,9 @@
with(change: { scheme?: string; authority?: string | null; path?: string | null; query?: string | null; fragment?: string | null }): URI {
if (!change) {
- return this;
- }
-
- let { scheme, authority, path, query, fragment } = change;
- if (scheme === undefined) {
- scheme = this.scheme;
- } else if (scheme === null) {
- scheme = _empty;
- }
- if (authority === undefined) {
- authority = this.authority;
- } else if (authority === null) {
- authority = _empty;
- }
- if (path === undefined) {
- path = this.path;
- } else if (path === null) {
- path = _empty;
- }
- if (query === undefined) {
- query = this.query;
- } else if (query === null) {
- query = _empty;
- }
- if (fragment === undefined) {
- fragment = this.fragment;
- } else if (fragment === null) {
- fragment = _empty;
- }
-
- if (scheme === this.scheme
- && authority === this.authority
- && path === this.path
- && query === this.query
- && fragment === this.fragment) {
-
- return this;
- }
-
+{ … 39 line(s) … ⟦tj:212723d05e5d1990128ee33d5201f061⟧ }
return new Uri(scheme, authority, path, query, fragment);
- }
+}
// ---- parse & validate ------------------------
@@ -267,17 +206,9 @@
static parse(value: string, _strict: boolean = false): URI {
const match = _regexp.exec(value);
if (!match) {
- return new Uri(_empty, _empty, _empty, _empty, _empty);
- }
- return new Uri(
- match[2] || _empty,
- percentDecode(match[4] || _empty),
- percentDecode(match[5] || _empty),
- percentDecode(match[7] || _empty),
- percentDecode(match[9] || _empty),
- _strict
+ { … 9 line(s) … ⟦tj:187ea2dc3fd36c99b3cc8df3c1f78448⟧ }
);
- }
+}
/**
* Creates a new URI from a file system path, e.g. `c:\my\files`,
@@ -301,31 +232,11 @@
* @param path A file system path (see `URI#fsPath`)
*/
static file(path: string): URI {
-
- let authority = _empty;
-
- // normalize to fwd-slashes on windows,
- // on other systems bwd-slashes are valid
- // filename character, eg /f\oo/ba\r.txt
- if (isWindows) {
- path = path.replace(/\\/g, _slash);
- }
-
- // check for authority as used in UNC shares
- // or use the path as given
- if (path[0] === _slash && path[1] === _slash) {
- const idx = path.indexOf(_slash, 2);
- if (idx === -1) {
- authority = path.substring(2);
- path = _slash;
- } else {
- authority = path.substring(2, idx);
- path = path.substring(idx) || _slash;
- }
- }
+ let authority = _empty;
+{ … 21 line(s) … ⟦tj:c9082ca90142cafbdd31326e10d450f5⟧ }
return new Uri('file', authority, path, _empty, _empty);
- }
+}
/**
* Creates new URI from uri components.
@@ -334,17 +245,7 @@
* validation and should be used for untrusted uri components retrieved from storage,
* user input, command arguments etc
*/
- static from(components: UriComponents, strict?: boolean): URI {
- const result = new Uri(
- components.scheme,
- components.authority,
- components.path,
- components.query,
- components.fragment,
- strict
- );
- return result;
- }
+ static from(components: UriComponents, strict?: boolean): URI { … 11 line(s) … ⟦tj:dee873aec4631e007eae19e14b9b170f⟧ }
/**
* Join a URI path with path fragments and normalizes the resulting path.
@@ -353,18 +254,7 @@
* @param pathFragment The path fragment to add to the URI path.
* @returns The resulting URI.
*/
- static joinPath(uri: URI, ...pathFragment: string[]): URI {
- if (!uri.path) {
- throw new Error(`[UriError]: cannot call joinPath on URI without path`);
- }
- let newPath: string;
- if (isWindows && uri.scheme === 'file') {
- newPath = URI.file(paths.win32.join(uriToFsPath(uri, true), ...pathFragment)).path;
- } else {
- newPath = paths.posix.join(uri.path, ...pathFragment);
- }
- return uri.with({ path: newPath });
- }
+ static joinPath(uri: URI, ...pathFragment: string[]): URI { … 12 line(s) … ⟦tj:61b9fa3fb681e1d82a759eeb62ed2996⟧ }
// ---- printing/externalize ---------------------------
@@ -401,18 +291,7 @@
static revive(data: UriComponents | URI | undefined): URI | undefined;
static revive(data: UriComponents | URI | null): URI | null;
static revive(data: UriComponents | URI | undefined | null): URI | undefined | null;
- static revive(data: UriComponents | URI | undefined | null): URI | undefined | null {
- if (!data) {
- return data;
- } else if (data instanceof URI) {
- return data;
- } else {
- const result = new Uri(data);
- result._formatted = (<UriState>data).external ?? null;
- result._fsPath = (<UriState>data)._sep === _pathSepMarker ? (<UriState>data).fsPath ?? null : null;
- return result;
- }
- }
+ static revive(data: UriComponents | URI | undefined | null): URI | undefined | null { … 12 line(s) … ⟦tj:59e69e3742912e28dc7c6fbd6417ec47⟧ }
[Symbol.for('debug.description')]() {
return `URI(${this.toString()})`;
@@ -427,16 +306,7 @@
fragment?: string;
}
-export function isUriComponents(thing: any): thing is UriComponents {
- if (!thing || typeof thing !== 'object') {
- return false;
- }
- return typeof (<UriComponents>thing).scheme === 'string'
- && (typeof (<UriComponents>thing).authority === 'string' || typeof (<UriComponents>thing).authority === 'undefined')
- && (typeof (<UriComponents>thing).path === 'string' || typeof (<UriComponents>thing).path === 'undefined')
- && (typeof (<UriComponents>thing).query === 'string' || typeof (<UriComponents>thing).query === 'undefined')
- && (typeof (<UriComponents>thing).fragment === 'string' || typeof (<UriComponents>thing).fragment === 'undefined');
-}
+export function isUriComponents(thing: any): thing is UriComponents { … 10 line(s) … ⟦tj:d85bd96bc51dc4877b8061060aa4c309⟧ }
interface UriState extends UriComponents {
$mid: MarshalledId.Uri;
@@ -460,54 +330,15 @@
return this._fsPath;
}
- override toString(skipEncoding: boolean = false): string {
- if (!skipEncoding) {
- if (!this._formatted) {
- this._formatted = _asFormatted(this, false);
- }
- return this._formatted;
- } else {
- // we don't cache that
- return _asFormatted(this, true);
- }
- }
+ override toString(skipEncoding: boolean = false): string { … 11 line(s) … ⟦tj:d74be94362da385e328912d10faafafb⟧ }
override toJSON(): UriComponents {
// eslint-disable-next-line local/code-no-dangerous-type-assertions
const res = <UriState>{
- $mid: MarshalledId.Uri
- };
- // cached state
- if (this._fsPath) {
- res.fsPath = this._fsPath;
- res._sep = _pathSepMarker;
- }
- if (this._formatted) {
- res.external = this._formatted;
- }
- //--- uri components
- if (this.path) {
- res.path = this.path;
- }
- // TODO
- // this isn't correct and can violate the UriComponents contract but
- // this is part of the vscode.Uri API and we shouldn't change how that
- // works anymore
- if (this.scheme) {
- res.scheme = this.scheme;
- }
- if (this.authority) {
- res.authority = this.authority;
- }
- if (this.query) {
- res.query = this.query;
- }
- if (this.fragment) {
- res.fragment = this.fragment;
- }
+ { … 30 line(s) … ⟦tj:c62499753706595e0d7002428baab8fa⟧ }
return res;
- }
}
+}
// reserved characters: https://tools.ietf.org/html/rfc3986#section-2.2
const encodeTable: { [ch: number]: string } = {
@@ -537,82 +368,14 @@
function encodeURIComponentFast(uriComponent: string, isPath: boolean, isAuthority: boolean): string {
let res: string | undefined = undefined;
let nativeEncodePos = -1;
-
- for (let pos = 0; pos < uriComponent.length; pos++) {
- const code = uriComponent.charCodeAt(pos);
-
- // unreserved characters: https://tools.ietf.org/html/rfc3986#section-2.3
- if (
- (code >= CharCode.a && code <= CharCode.z)
- || (code >= CharCode.A && code <= CharCode.Z)
- || (code >= CharCode.Digit0 && code <= CharCode.Digit9)
- || code === CharCode.Dash
- || code === CharCode.Period
- || code === CharCode.Underline
- || code === CharCode.Tilde
- || (isPath && code === CharCode.Slash)
- || (isAuthority && code === CharCode.OpenSquareBracket)
- || (isAuthority && code === CharCode.CloseSquareBracket)
- || (isAuthority && code === CharCode.Colon)
- ) {
- // check if we are delaying native encode
- if (nativeEncodePos !== -1) {
- res += encodeURIComponent(uriComponent.substring(nativeEncodePos, pos));
- nativeEncodePos = -1;
- }
- // check if we write into a new string (by default we try to return the param)
- if (res !== undefined) {
- res += uriComponent.charAt(pos);
- }
-
- } else {
- // encoding needed, we need to allocate a new string
- if (res === undefined) {
- res = uriComponent.substr(0, pos);
- }
-
- // check with default table first
- const escaped = encodeTable[code];
- if (escaped !== undefined) {
-
- // check if we are delaying native encode
- if (nativeEncodePos !== -1) {
- res += encodeURIComponent(uriComponent.substring(nativeEncodePos, pos));
- nativeEncodePos = -1;
- }
-
- // append escaped variant to result
- res += escaped;
-
- } else if (nativeEncodePos === -1) {
- // use native encode only when needed
- nativeEncodePos = pos;
- }
- }
- }
-
- if (nativeEncodePos !== -1) {
- res += encodeURIComponent(uriComponent.substring(nativeEncodePos));
- }
-
+ { … 58 line(s) … ⟦tj:4ab6816d1f5e5ec18d5fc3ff9b487604⟧ }
return res !== undefined ? res : uriComponent;
}
function encodeURIComponentMinimal(path: string): string {
let res: string | undefined = undefined;
for (let pos = 0; pos < path.length; pos++) {
- const code = path.charCodeAt(pos);
- if (code === CharCode.Hash || code === CharCode.QuestionMark) {
- if (res === undefined) {
- res = path.substr(0, pos);
- }
- res += encodeTable[code];
- } else {
- if (res !== undefined) {
- res += path[pos];
- }
- }
- }
+ { … 12 line(s) … ⟦tj:aec32af8b1e057b4e7976f6a3a4bd18e⟧ }
return res !== undefined ? res : path;
}
@@ -622,27 +385,7 @@
export function uriToFsPath(uri: URI, keepDriveLetterCasing: boolean): string {
let value: string;
- if (uri.authority && uri.path.length > 1 && uri.scheme === 'file') {
- // unc path: file://shares/c$/far/boo
- value = `//${uri.authority}${uri.path}`;
- } else if (
- uri.path.charCodeAt(0) === CharCode.Slash
- && (uri.path.charCodeAt(1) >= CharCode.A && uri.path.charCodeAt(1) <= CharCode.Z || uri.path.charCodeAt(1) >= CharCode.a && uri.path.charCodeAt(1) <= CharCode.z)
- && uri.path.charCodeAt(2) === CharCode.Colon
- ) {
- if (!keepDriveLetterCasing) {
- // windows drive letter: file:///c:/far/boo
- value = uri.path[1].toLowerCase() + uri.path.substr(2);
- } else {
- value = uri.path.substr(1);
- }
- } else {
- // other path
- value = uri.path;
- }
- if (isWindows) {
- value = value.replace(/\//g, '\\');
- }
+{ … 21 line(s) … ⟦tj:cf4dcabef15b1c3e4e2da59a4ada3f87⟧ }
return value;
}
@@ -652,86 +395,13 @@
function _asFormatted(uri: URI, skipEncoding: boolean): string {
const encoder = !skipEncoding
- ? encodeURIComponentFast
- : encodeURIComponentMinimal;
-
- let res = '';
- let { scheme, authority, path, query, fragment } = uri;
- if (scheme) {
- res += scheme;
- res += ':';
- }
- if (authority || scheme === 'file') {
- res += _slash;
- res += _slash;
- }
- if (authority) {
- let idx = authority.indexOf('@');
- if (idx !== -1) {
- // <user>@<auth>
- const userinfo = authority.substr(0, idx);
- authority = authority.substr(idx + 1);
- idx = userinfo.lastIndexOf(':');
- if (idx === -1) {
- res += encoder(userinfo, false, false);
- } else {
- // <user>:<pass>@<auth>
- res += encoder(userinfo.substr(0, idx), false, false);
- res += ':';
- res += encoder(userinfo.substr(idx + 1), false, true);
- }
- res += '@';
- }
- authority = authority.toLowerCase();
- idx = authority.lastIndexOf(':');
- if (idx === -1) {
- res += encoder(authority, false, true);
- } else {
- // <auth>:<port>
- res += encoder(authority.substr(0, idx), false, true);
- res += authority.substr(idx);
- }
- }
- if (path) {
- // lower-case windows drive letters in /C:/fff or C:/fff
- if (path.length >= 3 && path.charCodeAt(0) === CharCode.Slash && path.charCodeAt(2) === CharCode.Colon) {
- const code = path.charCodeAt(1);
- if (code >= CharCode.A && code <= CharCode.Z) {
- path = `/${String.fromCharCode(code + 32)}:${path.substr(3)}`; // "/c:".length === 3
- }
- } else if (path.length >= 2 && path.charCodeAt(1) === CharCode.Colon) {
- const code = path.charCodeAt(0);
- if (code >= CharCode.A && code <= CharCode.Z) {
- path = `${String.fromCharCode(code + 32)}:${path.substr(2)}`; // "/c:".length === 3
- }
- }
- // encode the rest of the path
- res += encoder(path, true, false);
- }
- if (query) {
- res += '?';
- res += encoder(query, false, false);
- }
- if (fragment) {
- res += '#';
- res += !skipEncoding ? encodeURIComponentFast(fragment, false, false) : fragment;
- }
+{ … 64 line(s) … ⟦tj:17b293d3fadb7801cd5e5f6d9764de2b⟧ }
return res;
}
// --- decode
-function decodeURIComponentGraceful(str: string): string {
- try {
- return decodeURIComponent(str);
- } catch {
- if (str.length > 3) {
- return str.substr(0, 3) + decodeURIComponentGraceful(str.substr(3));
- } else {
- return str;
- }
- }
-}
+function decodeURIComponentGraceful(str: string): string { … 11 line(s) … ⟦tj:017c7ac3071060da44d7af25f760ac69⟧ }
const _rEncodedAsHex = /(%[0-9A-Za-z][0-9A-Za-z])+/g;
@@ -748,3 +418,6 @@
export type UriDto<T> = { [K in keyof T]: T[K] extends URI
? UriComponents
: UriDto<T[K]> };
+[omitted blocks are individually retrievable: call tinyjuice_retrieve with the token inside an omission marker to expand just that block]
+
+[PARTIAL view — full original (22643 bytes): call tinyjuice_retrieve with token "4369ae3ad11dddac2f76c89b6e73d33c"]
\ No newline at end of file