Skip to content

Commit

Permalink
Propagate fix for repetitions from abnf translator (#323)
Browse files Browse the repository at this point in the history
We propagate the fix from [abnf-to-regex] where the max. repetitions
(`{, X}`) were mistakenly translated to exact repetitions (`{X}`) in the
regular expressions.
  • Loading branch information
mristin committed Mar 22, 2024
1 parent 79314c6 commit 4ee616c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
16 changes: 9 additions & 7 deletions aas_core_meta/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,10 @@ def matches_RFC_8089_path(text: str) -> bool:
ls32 = f"({h16}:{h16}|{ipv4address})"
ipv6address = (
f"(({h16}:){{6}}{ls32}|::({h16}:){{5}}{ls32}|({h16})?::({h16}:){{4}}"
f"{ls32}|(({h16}:)?{h16})?::({h16}:){{3}}{ls32}|(({h16}:){{2}}{h16})?::"
f"({h16}:){{2}}{ls32}|(({h16}:){{3}}{h16})?::{h16}:{ls32}|(({h16}:){{4}}"
f"{h16})?::{ls32}|(({h16}:){{5}}{h16})?::{h16}|(({h16}:){{6}}{h16})?::)"
f"{ls32}|(({h16}:)?{h16})?::({h16}:){{3}}{ls32}|(({h16}:){{,2}}{h16})?::"
f"({h16}:){{2}}{ls32}|(({h16}:){{,3}}{h16})?::{h16}:{ls32}|(({h16}:){{,4}}"
f"{h16})?::{ls32}|(({h16}:){{,5}}{h16})?::{h16}|(({h16}:){{,6}}{h16})?"
"::)"
)
unreserved = "[a-zA-Z0-9\\-._~]"
sub_delims = "[!$&'()*+,;=]"
Expand Down Expand Up @@ -281,7 +282,7 @@ def matches_BCP_47(text: str) -> bool:
alphanum = "[a-zA-Z0-9]"
singleton = "[0-9A-WY-Za-wy-z]"
extension = f"{singleton}(-({alphanum}){{2,8}})+"
extlang = "[a-zA-Z]{3}(-[a-zA-Z]{3}){2}"
extlang = "[a-zA-Z]{3}(-[a-zA-Z]{3}){,2}"
irregular = (
"(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|"
"i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|"
Expand Down Expand Up @@ -398,9 +399,10 @@ def matches_xs_any_URI(text: str) -> bool:
ls32 = f"({h16}:{h16}|{ipv4address})"
ipv6address = (
f"(({h16}:){{6}}{ls32}|::({h16}:){{5}}{ls32}|({h16})?::({h16}:){{4}}"
f"{ls32}|(({h16}:)?{h16})?::({h16}:){{3}}{ls32}|(({h16}:){{2}}{h16})?::"
f"({h16}:){{2}}{ls32}|(({h16}:){{3}}{h16})?::{h16}:{ls32}|(({h16}:){{4}}"
f"{h16})?::{ls32}|(({h16}:){{5}}{h16})?::{h16}|(({h16}:){{6}}{h16})?::)"
f"{ls32}|(({h16}:)?{h16})?::({h16}:){{3}}{ls32}|(({h16}:){{,2}}{h16})?::"
f"({h16}:){{2}}{ls32}|(({h16}:){{,3}}{h16})?::{h16}:{ls32}|(({h16}:){{,4}}"
f"{h16})?::{ls32}|(({h16}:){{,5}}{h16})?::{h16}|(({h16}:){{,6}}{h16})?"
"::)"
)
unreserved = "[a-zA-Z0-9\\-._~]"
ipvfuture = f"[vV][0-9A-Fa-f]+\\.({unreserved}|{sub_delims}|:)+"
Expand Down
16 changes: 9 additions & 7 deletions aas_core_meta/v3_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,10 @@ def matches_RFC_8089_path(text: str) -> bool:
ls32 = f"({h16}:{h16}|{ipv4address})"
ipv6address = (
f"(({h16}:){{6}}{ls32}|::({h16}:){{5}}{ls32}|({h16})?::({h16}:){{4}}"
f"{ls32}|(({h16}:)?{h16})?::({h16}:){{3}}{ls32}|(({h16}:){{2}}{h16})?::"
f"({h16}:){{2}}{ls32}|(({h16}:){{3}}{h16})?::{h16}:{ls32}|(({h16}:){{4}}"
f"{h16})?::{ls32}|(({h16}:){{5}}{h16})?::{h16}|(({h16}:){{6}}{h16})?::)"
f"{ls32}|(({h16}:)?{h16})?::({h16}:){{3}}{ls32}|(({h16}:){{,2}}{h16})?::"
f"({h16}:){{2}}{ls32}|(({h16}:){{,3}}{h16})?::{h16}:{ls32}|(({h16}:){{,4}}"
f"{h16})?::{ls32}|(({h16}:){{,5}}{h16})?::{h16}|(({h16}:){{,6}}{h16})?"
"::)"
)
unreserved = "[a-zA-Z0-9\\-._~]"
sub_delims = "[!$&'()*+,;=]"
Expand Down Expand Up @@ -281,7 +282,7 @@ def matches_BCP_47(text: str) -> bool:
alphanum = "[a-zA-Z0-9]"
singleton = "[0-9A-WY-Za-wy-z]"
extension = f"{singleton}(-({alphanum}){{2,8}})+"
extlang = "[a-zA-Z]{3}(-[a-zA-Z]{3}){2}"
extlang = "[a-zA-Z]{3}(-[a-zA-Z]{3}){,2}"
irregular = (
"(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|"
"i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|"
Expand Down Expand Up @@ -398,9 +399,10 @@ def matches_xs_any_URI(text: str) -> bool:
ls32 = f"({h16}:{h16}|{ipv4address})"
ipv6address = (
f"(({h16}:){{6}}{ls32}|::({h16}:){{5}}{ls32}|({h16})?::({h16}:){{4}}"
f"{ls32}|(({h16}:)?{h16})?::({h16}:){{3}}{ls32}|(({h16}:){{2}}{h16})?::"
f"({h16}:){{2}}{ls32}|(({h16}:){{3}}{h16})?::{h16}:{ls32}|(({h16}:){{4}}"
f"{h16})?::{ls32}|(({h16}:){{5}}{h16})?::{h16}|(({h16}:){{6}}{h16})?::)"
f"{ls32}|(({h16}:)?{h16})?::({h16}:){{3}}{ls32}|(({h16}:){{,2}}{h16})?::"
f"({h16}:){{2}}{ls32}|(({h16}:){{,3}}{h16})?::{h16}:{ls32}|(({h16}:){{,4}}"
f"{h16})?::{ls32}|(({h16}:){{,5}}{h16})?::{h16}|(({h16}:){{,6}}{h16})?"
"::)"
)
unreserved = "[a-zA-Z0-9\\-._~]"
ipvfuture = f"[vV][0-9A-Fa-f]+\\.({unreserved}|{sub_delims}|:)+"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_free_form_text(self) -> None:
assert not v3.matches_BCP_47("some free form text")

def test_valid(self) -> None:
for text in ["de", "de-CH"]:
for text in ["de", "de-CH", "zh-cmn-Hans-CN"]:
self.assertTrue(v3.matches_BCP_47(text), text)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_v3_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_free_form_text(self) -> None:
assert not v3_1.matches_BCP_47("some free form text")

def test_valid(self) -> None:
for text in ["de", "de-CH"]:
for text in ["de", "de-CH", "zh-cmn-Hans-CN"]:
self.assertTrue(v3_1.matches_BCP_47(text), text)


Expand Down

0 comments on commit 4ee616c

Please sign in to comment.