Unescaped Regex

#19 · closed · 2 comments

View on GitHub ↗

brentonmallen1

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](https://github.com/goauthentik/authentik/issues/8936). 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.

Comments

brentonmallen1

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

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]))+') >>> ```