未验证 提交 e0140fac 编写于 作者: I Isidor Nikolic 提交者: GitHub

Merge pull request #50869 from Krzysztof-Cieslak/fix50820

Add support for `1.txt` format in incrementFileName
......@@ -1083,6 +1083,17 @@ export function incrementFileName(name: string, isFolder: boolean): string {
});
}
// 1.txt=>2.txt
let prefixFileNoNameRegex = RegExp('(\\d+)(\\..*)$');
if (!isFolder && name.match(prefixFileNoNameRegex)) {
return name.replace(prefixFileNoNameRegex, (match, g1?, g2?) => {
let number = parseInt(g1);
return number < maxNumber
? strings.pad(number + 1, g1.length) + g2
: strings.format('{0}.1{1}', g1, g2);
});
}
// file.txt=>file.1.txt
const lastIndexOfDot = name.lastIndexOf('.');
if (!isFolder && lastIndexOfDot >= 0) {
......
......@@ -106,6 +106,18 @@ suite('Files - Increment file name', () => {
assert.strictEqual(result, '2.test.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, too big number', function () {
const name = '9007199254740992.js';
const result = incrementFileName(name, false);
assert.strictEqual(result, '9007199254740992.1.js');
});
test('Increment file name with prefix version, trailing zeros', function () {
const name = '001.test.js';
const result = incrementFileName(name, false);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册