Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix realCasePath changing empty paths to . #6001

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/common/pathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ export function stripFileExtension(fileName: string, multiDotExtension = false)
}

export function realCasePath(pathString: string, fileSystem: ReadOnlyFileSystem): string {
return normalizePath(fileSystem.realCasePath(pathString));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This normalizePath can change the empty string into a .. We shouldn't need to normalize since calling real case o n a path will have that same effect anyway.

return fileSystem.realCasePath(pathString);
}

export function normalizePath(pathString: string): string {
Expand Down
27 changes: 24 additions & 3 deletions packages/pyright-internal/src/tests/pathUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import assert from 'assert';
import * as nodefs from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
import * as nodefs from 'fs-extra';

import { expandPathVariables } from '../common/envVarUtils';
import {
Expand All @@ -35,13 +35,14 @@ import {
isFileSystemCaseSensitiveInternal,
isRootedDiskPath,
normalizeSlashes,
realCasePath,
reducePathComponents,
resolvePaths,
stripFileExtension,
stripTrailingDirectorySeparator,
} from '../common/pathUtils';
import * as vfs from './harness/vfs/filesystem';
import { createFromRealFileSystem } from '../common/realFileSystem';
import * as vfs from './harness/vfs/filesystem';

test('getPathComponents1', () => {
const components = getPathComponents('');
Expand Down Expand Up @@ -390,12 +391,32 @@ test('convert UNC path', () => {
test('Realcase', () => {
const fs = createFromRealFileSystem();
const cwd = process.cwd();
const dir = path.join(cwd, 'src', 'tests');
const dir = path.join(cwd, 'src', 'tests', '..', 'tests');
const entries = nodefs.readdirSync(dir).map((entry) => path.basename(nodefs.realpathSync(path.join(dir, entry))));
const fsentries = fs.readdirSync(dir);
assert.deepStrictEqual(entries, fsentries);

const paths = entries.map((entry) => nodefs.realpathSync(path.join(dir, entry)));
const fspaths = fsentries.map((entry) => fs.realCasePath(path.join(dir, entry)));
assert.deepStrictEqual(paths, fspaths);

for (const p of fspaths) {
const upper = p.toUpperCase();
const real = fs.realCasePath(upper);
assert.strictEqual(p, real);
}
});

test('Realcase use cwd implicitly', () => {
const fs = createFromRealFileSystem();
const empty = realCasePath('', fs);
assert.deepStrictEqual(empty, '');
const cwd = process.cwd();
const dir = path.join(cwd, 'src', 'tests');

const entries = nodefs.readdirSync(dir).map((entry) => path.basename(nodefs.realpathSync(path.join(dir, entry))));
const fsentries = fs.readdirSync(path.join('src', 'tests'));
const paths = entries.map((entry) => nodefs.realpathSync(path.join(dir, entry)));
const fspaths = fsentries.map((entry) => fs.realCasePath(path.join(dir, entry)));
assert.deepStrictEqual(paths, fspaths);
});
Loading