Skip to content

Fix MaxNumber incrementFileName bug - #50865

Merged
Isidor Nikolic (isidorn) merged 2 commits into
microsoft:masterfrom
Krzysztof-Cieslak:fix50822
May 31, 2018
Merged

Isidor Nikolic (isidorn) merged 2 commits into
microsoft:masterfrom
Krzysztof-Cieslak:fix50822

Conversation

@Krzysztof-Cieslak

Copy link
Copy Markdown
Contributor


export function incrementFileName(name: string, isFolder: boolean): string {
const separators = '[\\.\\-_]';
const maxNumber = 9007199254740991;

@Krzysztof-Cieslak Krzysztof Cieślak (Krzysztof-Cieslak) May 31, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It looks like TS bindings are not exposing Number.MAX_SAFE_INTEGER (it was added in ES6 as far as I remember)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated


export function incrementFileName(name: string, isFolder: boolean): string {
const separators = '[\\.\\-_]';
const maxNumber = 9007199254740991;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

let suffixFileRegex = RegExp('(.*' + separators + ')(\\d+)(\\..*)$');
if (!isFolder && name.match(suffixFileRegex)) {
return name.replace(suffixFileRegex, (match, g1?, g2?, g3?) => {
return g1 + strings.pad(parseInt(g2) + 1, g2.length) + g3;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we have a helper method for this?
Since this code seems like it is duplicated 4 times?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's bit different for every case since it formats the string in different formats, not sure if there is a sense in trying to extract that to helper function.

@@ -88,6 +88,18 @@ suite('Files - Increment file name', () => {
assert.strictEqual(result, 'test_2');
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great job with tests

@isidorn

Copy link
Copy Markdown

Thanks for this PR. I have commented directly in the code. Once that is addressed we can merge this in. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hang when copy/pasting file with large number

2 participants