Skip to content

Commit

Permalink
Fix for the case no min. and only max. repetition
Browse files Browse the repository at this point in the history
We mistakenly omitted to mark a maximum repetition without an exactly
specified minimum, and represented it as an exact repetition.

The bug was revealed on tests with BCP47.
  • Loading branch information
mristin committed Mar 22, 2024
1 parent fa0ea08 commit ae3ff0f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion abnf_to_regexp/nested_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def visit_repetition(self, element: Repetition) -> None:
and element.max_occurrences is not None
and element.max_occurrences > 0
):
suffix = f"{{{element.max_occurrences}}}"
suffix = f"{{,{element.max_occurrences}}}"
elif (
element.min_occurrences is not None
and element.min_occurrences > 0
Expand Down
2 changes: 1 addition & 1 deletion test_data/nested-python/bcp47/expected.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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
7 changes: 4 additions & 3 deletions test_data/nested-python/rfc3986/expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
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})?'
'::)'
)
ipvfuture = f'[vV][0-9A-Fa-f]+\\.({unreserved}|{sub_delims}|:)+'
ip_literal = f'\\[({ipv6address}|{ipvfuture})\\]'
Expand Down
7 changes: 4 additions & 3 deletions test_data/nested-python/rfc3987/expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
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
7 changes: 4 additions & 3 deletions test_data/nested-python/rfc8089/expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
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

0 comments on commit ae3ff0f

Please sign in to comment.