s3tools / s3cmd

Official s3cmd repo -- Command line tool for managing S3 compatible storage services (including Amazon S3 and CloudFront).
https://s3tools.org/s3cmd
GNU General Public License v2.0
4.54k stars 903 forks source link

SyntaxWarnings "invalid escape sequence" in S3Uri.py and FileLists.py #1374

Open TurtleWilly opened 4 months ago

TurtleWilly commented 4 months ago

I do encounter a heap of warnings (yes, I zipapp'ed s3cmd) which suggest proper bugs:

$ ./s3cmd.pyz --version
/Volumes/Temporary/s3cmd/./s3cmd.pyz/S3/S3Uri.py:122: SyntaxWarning: invalid escape sequence '\.'
/Volumes/Temporary/s3cmd/./s3cmd.pyz/S3/S3Uri.py:170: SyntaxWarning: invalid escape sequence '\w'
/Volumes/Temporary/s3cmd/./s3cmd.pyz/S3/S3Uri.py:122: SyntaxWarning: invalid escape sequence '\.'
/Volumes/Temporary/s3cmd/./s3cmd.pyz/S3/S3Uri.py:170: SyntaxWarning: invalid escape sequence '\w'
/Volumes/Temporary/s3cmd/./s3cmd.pyz/S3/FileLists.py:525: SyntaxWarning: invalid escape sequence '\*'
/Volumes/Temporary/s3cmd/./s3cmd.pyz/S3/FileLists.py:525: SyntaxWarning: invalid escape sequence '\*'
s3cmd version 2.4.0

The reported regex strings should be prefixed with "r" to become raw strings (like r".*\..*") or the backslashes need to be double escaped (like ".*\\..*"). I recommend the first option.

Note that a simple backslash triggers string escaping only (like "\n" or "\e", f.ex.), but what you are trying to achieve there is to escape characters from the regex (e.g. "." for a literal dot character and not "any character") or use special regex sequences (like "\w").

TurtleWilly commented 4 months ago

I just found out that there is already a fix in the queue: https://github.com/s3tools/s3cmd/pull/1370