MatchesRfc8089Path🔗
Check that
text
is a path conforming to the pattern of RFC 8089.
The definition has been taken from:
https://datatracker.ietf.org/doc/html/rfc8089
Code
h16 = (
'[0-9A-Fa-f]{1,4}'
)
decOctet = (
'([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])'
)
ipv4address = (
f'{decOctet}\\.{decOctet}\\.{decOctet}\\.{decOctet}'
)
ls32 = (
f'({h16}:{h16}|{ipv4address})'
)
ipv6address = (
f'(({h16}:){{6}}{ls32}|::({h16}:){{5}}{ls32}|({h16})?::({h16}:){{4}}{ls32}|(({h16}:)?{h16})?::({h16}:){{3}}{ls32}|(({h16}:){{2}}{h16})?::({h16}:){{2}}{ls32}|(({h16}:){{3}}{h16})?::{h16}:{ls32}|(({h16}:){{4}}{h16})?::{ls32}|(({h16}:){{5}}{h16})?::{h16}|(({h16}:){{6}}{h16})?::)'
)
unreserved = (
'[a-zA-Z0-9\\-._~]'
)
subDelims = (
"[!$&'()*+,;=]"
)
ipvfuture = (
f'[vV][0-9A-Fa-f]+\\.({unreserved}|{subDelims}|:)+'
)
ipLiteral = (
f'\\[({ipv6address}|{ipvfuture})\\]'
)
pctEncoded = (
'%[0-9A-Fa-f][0-9A-Fa-f]'
)
regName = (
f'({unreserved}|{pctEncoded}|{subDelims})*'
)
host = (
f'({ipLiteral}|{ipv4address}|{regName})'
)
fileAuth = (
f'(localhost|{host})'
)
pchar = (
f'({unreserved}|{pctEncoded}|{subDelims}|[:@])'
)
segmentNz = (
f'({pchar})+'
)
segment = (
f'({pchar})*'
)
pathAbsolute = (
f'/({segmentNz}(/{segment})*)?'
)
authPath = (
f'({fileAuth})?{pathAbsolute}'
)
localPath = (
f'{pathAbsolute}'
)
fileHierPart = (
f'(//{authPath}|{localPath})'
)
fileScheme = 'file'
fileUri = (
f'{fileScheme}:{fileHierPart}'
)
pattern = (
f'^{fileUri}$'
)
return match(
pattern,
text
) is not None