src/vs/base/common/envfile.ts

100 LOC · 96 covered · 4 uncovered · 4 ranges · 3 concepts · 2 introducers · 7 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

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 related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the fileextHostMcpNode.ts ×8 · 45 introduced LOCextHostMcpNode.ts ×8envfile.ts ×3 · 82 introduced LOCenvfile.ts ×3envfile.ts ×1 · 14 introduced LOCenvfile.ts ×1envfile.test|title=parseEnvFile parses|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/envfile.test|title=parseEnvFile parses|occurrence=1envfile.test|title=parse…extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg does not add stray ^ to argument values|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg does not add stray ^ to argument values|occurrence=1extHostMcpNode.test|titl…extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg doubles embedded double quotes (cmd.exe convention)|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg doubles embedded double quotes (cmd.exe convention)|occurrence=1extHostMcpNode.test|titl…extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg neutralizes cmd.exe metacharacters inside quotes (CVE-2024-27980)|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg neutralizes cmd.exe metacharacters inside quotes (CVE-2024-27980)|occurrence=1extHostMcpNode.test|titl…extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg preserves paths with parentheses without injecting ^|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg preserves paths with parentheses without injecting ^|occurrence=1extHostMcpNode.test|titl…extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg preserves paths with spaces|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg preserves paths with spaces|occurrence=1extHostMcpNode.test|titl…extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg wraps simple values in double quotes|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostMcpNode.test|title=extHostMcpNode - escapeCmdArg wraps simple values in double quotes|occurrence=1extHostMcpNode.test|titl…Focused file · src/vs/base/common/envfile.ts · 100 LOCcommon/envfile.ts

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- envfile.ts ×1
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > /**
7 > * Parses a standard .env/.envrc file into a map of the environment variables
8 > * it defines.
9 > *
10 > * todo@connor4312: this can go away (if only used in Node.js targets) and be
11 > * replaced with `util.parseEnv`. However, currently calling that makes the
12 > * extension host crash.
13 > */
14 > export function parseEnvFile(src: string) {
15 > const result = new Map<string, string>(); envfile.ts ×3
16 >
17 > // Normalize line breaks
18 > const normalizedSrc = src.replace(/\r\n?/g, '\n');
19 > const lines = normalizedSrc.split('\n');
20 >
21 > for (let line of lines) {
22 > // Skip empty lines and comments
23 > line = line.trim();
24 > if (!line || line.startsWith('#')) {
25 > continue;
26 > }
27 >
28 > // Parse the line into key and value
29 > const [key, value] = parseLine(line);
30 > if (key) {
31 > result.set(key, value);
32 > }
33 > }
34 >
35 > return result;
36 >
37 > function parseLine(line: string): [string, string] | [null, null] {
38 > // Handle export prefix
39 > if (line.startsWith('export ')) {
40 line = line.substring(7).trim();
41 }
43 > // Find the key-value separator
44 > const separatorIndex = findIndexOutsideQuotes(line, c => c === '=' || c === ':');
45 > if (separatorIndex === -1) {
46 return [null, null];
47 }
49 > const key = line.substring(0, separatorIndex).trim();
50 > let value = line.substring(separatorIndex + 1).trim();
51 >
52 > // Handle comments and remove them
53 > const commentIndex = findIndexOutsideQuotes(value, c => c === '#');
54 > if (commentIndex !== -1) {
55 > value = value.substring(0, commentIndex).trim();
56 > }
57 >
58 > // Process quoted values
59 > if (value.length >= 2) {
60 > const firstChar = value[0];
61 > const lastChar = value[value.length - 1];
62 >
63 > if ((firstChar === '"' && lastChar === '"') ||
64 > (firstChar === '\'' && lastChar === '\'') ||
65 > (firstChar === '`' && lastChar === '`')) {
66 > // Remove surrounding quotes
67 > value = value.substring(1, value.length - 1);
68 >
69 > // Handle escaped characters in double quotes
70 > if (firstChar === '"') {
71 > value = value.replace(/\\n/g, '\n').replace(/\\r/g, '\r');
72 > }
73 > }
74 > }
75 >
76 > return [key, value];
77 > }
78 >
79 > function findIndexOutsideQuotes(text: string, predicate: (char: string) => boolean): number {
80 > let inQuote = false;
81 > let quoteChar = '';
82 >
83 > for (let i = 0; i < text.length; i++) {
84 > const char = text[i];
85 >
86 > if (inQuote) {
87 > if (char === quoteChar && text[i - 1] !== '\\') {
88 > inQuote = false;
89 > }
90 > } else if (char === '"' || char === '\'' || char === '`') {
91 > inQuote = true;
92 > quoteChar = char;
93 > } else if (predicate(char)) {
94 > return i;
95 > }
96 > }
97 >
98 > return -1;
99 > }
100 > }