Skip to content

Invalid regex when parsing ASN #84

Description

@bsmith1180

This is closely related to issue #83. The regex at line 243 in init.py is buggy.

The regex in question is

"^[AS]|[as]|[aS]|[As]][0-9]*(\.)?[0-9]+"

There's 2 issues:

  • Bug A: Extra ] (an unmatched closing bracket) in [As]]
  • Bug B: The Alternation Is Broken. Because | has low precedence, this means:

(^[AS]) OR ([as]) OR ([aS]) OR ([As]])

Which means:

^[AS] is anchored
The other alternatives are NOT anchored
The numeric part only applies to the last branch
So the regex does not enforce:

AS123
AS1.234

correctly.

Suggestion is to use

pattern = re.compile(r"(?i)^as\d+(\.\d+)?$")

Or simply merge the PR that has a more complete fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions