Skip to content

Unescaped Regex #19

Closed
Closed

Description

@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.

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.

Activity

  1. brentonmallen1 commented on May 9, 2024

    @brentonmallen1
    Author

    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.

  2. BeryJu commented on Aug 5, 2024

    @BeryJu
    Contributor

    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]))+')
    >>>
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions