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

Make sure prefix detection starts from start of the file name #55961

Merged
merged 1 commit into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/vs/workbench/parts/files/electron-browser/fileActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ export function incrementFileName(name: string, isFolder: boolean): string {
}

// 1.file.txt=>2.file.txt
let prefixFileRegex = RegExp('(\\d+)(' + separators + '.*)(\\..*)$');
let prefixFileRegex = RegExp('^(\\d+)(' + separators + '.*)(\\..*)$');
if (!isFolder && name.match(prefixFileRegex)) {
return name.replace(prefixFileRegex, (match, g1?, g2?, g3?) => {
let number = parseInt(g1);
Expand All @@ -1060,7 +1060,7 @@ export function incrementFileName(name: string, isFolder: boolean): string {
}

// 1.txt=>2.txt
let prefixFileNoNameRegex = RegExp('(\\d+)(\\..*)$');
let prefixFileNoNameRegex = RegExp('^(\\d+)(\\..*)$');
if (!isFolder && name.match(prefixFileNoNameRegex)) {
return name.replace(prefixFileNoNameRegex, (match, g1?, g2?) => {
let number = parseInt(g1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,24 @@ suite('Files - Increment file name', () => {
assert.strictEqual(result, '2.test.js');
});

test('Increment file name with prefix version - check if starting from digit', function () {
const name = 'F1.test.js';
const result = incrementFileName(name, false);
assert.strictEqual(result, 'F1.test.1.js');
});

test('Increment file name with just version in name', function () {
const name = '1.js';
const result = incrementFileName(name, false);
assert.strictEqual(result, '2.js');
});

test('Increment file name with just version in name - check if starting from digit', function () {
const name = 'F1.js';
const result = incrementFileName(name, false);
assert.strictEqual(result, 'F1.1.js');
});

test('Increment file name with just version in name, too big number', function () {
const name = '9007199254740992.js';
const result = incrementFileName(name, false);
Expand Down