Skip to content

Commit 0a4e300

Browse files
authored
Merge pull request #3 from ericksc/feature/hu-04-require-prefix-length-strict-cidr
HU-04: Require numeric prefix in strict CIDR mode
2 parents a77ed6f + 1980ebc commit 0a4e300

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎.github/workflows/pycqa.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: pycqa
33
on:
44
workflow_dispatch:
55
push:
6-
branches: [master]
6+
branches: [master, release]
77
pull_request:
8-
branches: [master]
8+
branches: [master, release]
99
jobs:
1010
tooling:
1111
runs-on: ubuntu-latest

‎.github/workflows/sast.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ name: sast
44
on:
55
workflow_dispatch:
66
push:
7-
branches: ["master"]
7+
branches: ["master", "release"]
88
pull_request:
9-
branches: ["master"]
9+
branches: ["master", "release"]
1010

1111
jobs:
1212
sast:

‎src/validators/ip_address.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""IP Address."""
22

3+
# cosmetic: no functional change (CI trigger demo)
34
# standard
45
from ipaddress import (
56
AddressValueError,
@@ -88,6 +89,10 @@ def ipv4(
8889
if cidr:
8990
if strict and value.count("/") != 1:
9091
raise ValueError("IPv4 address was expected in CIDR notation")
92+
if strict:
93+
_, prefix = value.split("/")
94+
if not prefix.isdigit() or not (0 <= int(prefix) <= 32):
95+
raise ValueError("CIDR prefix must be a number between 0 and 32")
9196
return IPv4Network(value, strict=not host_bit) and _check_private_ip(value, private)
9297
return IPv4Address(value) and _check_private_ip(value, private)
9398
except (ValueError, AddressValueError, NetmaskValueError):

0 commit comments

Comments
 (0)