Skip to content

Commit 488a151

Browse files
authored
Relax path validations (ignore %) (#2006)
* Relax path validations (ignore %) * Allow trailing path delimiters * Update message with solution
1 parent cde8e1e commit 488a151

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

src/client/application/diagnostics/applicationDiagnostics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class ApplicationDiagnostics implements IApplicationDiagnostics {
2727
const logger = this.serviceContainer.get<ILogger>(ILogger);
2828
const outputChannel = this.serviceContainer.get<IOutputChannel>(IOutputChannel, STANDARD_OUTPUT_CHANNEL);
2929
diagnostics.forEach(item => {
30-
const message = `Diagnostic Code: ${item.code}, Mesage: ${item.message}`;
30+
const message = `Diagnostic Code: ${item.code}, Message: ${item.message}`;
3131
switch (item.severity) {
3232
case DiagnosticSeverity.Error: {
3333
logger.logError(message);

src/client/application/diagnostics/checks/envPathVariable.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import { DiagnosticCodes } from '../constants';
1616
import { DiagnosticCommandPromptHandlerServiceId, MessageCommandPrompt } from '../promptHandler';
1717
import { DiagnosticScope, IDiagnostic, IDiagnosticHandlerService } from '../types';
1818

19-
const InvalidEnvPathVariableMessage = 'The environment variable \'{0}\' seems to have some paths containing characters (\';\', \'"\', \'%\' or \';;\').' +
20-
' The existence of such characters are known to have caused the {1} extension to not load.';
19+
const InvalidEnvPathVariableMessage = 'The environment variable \'{0}\' seems to have some paths containing characters (\';\', \'"\' or \';;\').' +
20+
' The existence of such characters are known to have caused the {1} extension to not load. If the extension fails to load please modify your paths to remove these characters.';
2121

2222
export class InvalidEnvironmentPathVariableDiagnostic extends BaseDiagnostic {
2323
constructor(message) {
@@ -79,6 +79,6 @@ export class EnvironmentPathVariableDiagnosticsService extends BaseDiagnosticsSe
7979
const pathValue = currentProc.env[this.platform.pathVariableName];
8080
const pathSeparator = this.serviceContainer.get<IPathUtils>(IPathUtils).delimiter;
8181
const paths = pathValue.split(pathSeparator);
82-
return paths.filter(item => item.indexOf('"') >= 0 || item.indexOf(';') >= 0 || item.indexOf('%') >= 0 || item.length === 0).length > 0;
82+
return paths.filter((item, index) => item.indexOf('"') >= 0 || item.indexOf(';') >= 0 || (item.length === 0 && index !== paths.length - 1)).length > 0;
8383
}
8484
}

src/test/application/diagnostics/applicationDiagnostics.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ suite('Application Diagnostics - ApplicationDiagnostics', () => {
7979
}
8080

8181
for (const diagnostic of diagnostics) {
82-
const message = `Diagnostic Code: ${diagnostic.code}, Mesage: ${diagnostic.message}`;
82+
const message = `Diagnostic Code: ${diagnostic.code}, Message: ${diagnostic.message}`;
8383
switch (diagnostic.severity) {
8484
case DiagnosticSeverity.Error: {
8585
logger.setup(l => l.logError(message))

src/test/application/diagnostics/checks/envPathVariable.unit.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ suite('Application Diagnostics - Checks Env Path Variable', () => {
114114

115115
expect(diagnostics).to.be.deep.equal([]);
116116
});
117-
[';;', '"', '%'].forEach(invalidCharacter => {
117+
// Note: On windows, when a path contains a `;` then Windows encloses the path within `"`.
118+
[';;', '"'].forEach(invalidCharacter => {
118119
test(`Should return single diagnostics for Windows if path contains ${invalidCharacter}`, async () => {
119120
platformService.setup(p => p.isWindows).returns(() => true);
120121
const paths = [
@@ -132,6 +133,18 @@ suite('Application Diagnostics - Checks Env Path Variable', () => {
132133
expect(diagnostics[0].severity).to.be.equal(DiagnosticSeverity.Warning);
133134
expect(diagnostics[0].scope).to.be.equal(DiagnosticScope.Global);
134135
});
136+
test('Should not return diagnostics for Windows if path ends with delimiter', async () => {
137+
const paths = [
138+
path.join('one', 'two', 'three'),
139+
path.join('one', 'two', 'four')
140+
].join(pathDelimiter) + pathDelimiter;
141+
platformService.setup(p => p.isWindows).returns(() => true);
142+
procEnv.setup(env => env[pathVariableName]).returns(() => paths);
143+
144+
const diagnostics = await diagnosticService.diagnose();
145+
146+
expect(diagnostics).to.be.lengthOf(0);
147+
});
135148
});
136149
test('Should display three options in message displayed with 2 commands', async () => {
137150
platformService.setup(p => p.isWindows).returns(() => true);

0 commit comments

Comments
 (0)