vsoch / oci-python

Python implementation of Open Containers Initiative (OCI) specifications
https://vsoch.github.io/oci-python/
Mozilla Public License 2.0
23 stars 12 forks source link

Unescaped Regex #19

Closed brentonmallen1 closed 4 months ago

brentonmallen1 commented 4 months ago

There's a regex pattern in https://github.com/vsoch/oci-python/blob/master/opencontainers/distribution/reggie/defaults.py#L17 that doesn't properly escape the / characters. It's unclear to me at the moment what's changed (other than python updates) have have caused this to be an issue in particularly for Authentik.

I'm not quite clear on the preferred contribution method here, but I'll at least fork and create a PR for this change and see if that's helpful.

brentonmallen1 commented 4 months ago

actually, it looks like it's just a warning so something else might be going on, but I'll make the PR all the same.

BeryJu commented 1 month ago

I dont think the PR fully fixes the issue, at least its still raising a warning in python 3.12.4

I suppose the fix would be using r"" instead of escaping it:

>>> from re import *
>>>
>>> # old regex
>>> compile("http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+")
<stdin>:1: SyntaxWarning: invalid escape sequence '\('
re.compile('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+')
>>> # new regex
>>> compile("http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+")
<stdin>:1: SyntaxWarning: invalid escape sequence '\/'
re.compile('http[s]?:\\/\\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+')
>>>
>>>
>>> # fixed
>>> compile(r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+")
re.compile('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+')
>>>