AdamRaichu / vscode-zip-viewer

An extension which allows for the manipulation of zip files in VS Code.
https://marketplace.visualstudio.com/items?itemName=AdamRaichu.zip-viewer
MIT License
10 stars 0 forks source link

bug: Regex characters in file names are not escaped when zipping a folder #96

Closed AdamRaichu closed 5 months ago

AdamRaichu commented 5 months ago

Describe the bug When zipping a folder that has square brackets [] or other

To Reproduce Steps to reproduce the behavior:

  1. Create a folder named Example [Folder].
  2. Add a file to the folder.
  3. Right-click the folder and zip it using the extension.
  4. Try to open the zip file.
  5. The zip file contains no files.

Expected behavior The zip file should contain files.

Environment What type of VS Code were you using when you encountered the problem?

Windows, but this should affect all platforms.

Additional context Add any other context about the problem here.

No error is shown with this example folder name, but errors do occur with unclosed brackets.

The code in question:

https://github.com/AdamRaichu/vscode-zip-viewer/blob/9f271ba008ba69e2a7edd16c40a0d81115eb7e20/src/cmds.js#L130

Should add the following function to fix.

// From https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
function escapeRegExp(string) {
    return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}