@@ -21,6 +21,9 @@ def __init__(self, input: typing.Any):
2121 r"^https?://(?P<hash>[^/]+)\.(?P<protocol>ip[fn]s)\.[^/?]+"
2222 )
2323 self .path_pattern = re .compile (r"^/(?P<protocol>ip[fn]s)/(?P<hash>[^/?#]+)" )
24+ self .native_url_pattern = re .compile (
25+ r"^(?P<protocol>ip[fn]s)://(?P<hash>[^/?#]+)"
26+ )
2427
2528 def is_ipfs (self ) -> bool :
2629 """
@@ -32,6 +35,8 @@ def is_ipfs(self) -> bool:
3235 or self ._is_ipns_url ()
3336 or self ._is_ipfs_path ()
3437 or self ._is_ipns_path ()
38+ or self ._is_native_ipfs_url ()
39+ or self ._is_native_ipns_url ()
3540 )
3641
3742 def _is_cid (self ) -> bool :
@@ -75,7 +80,10 @@ def _is_integral_ipfs_url(
7580
7681 _hash = match ["hash" ]
7782
78- if pattern == self .subdomain_gateway_pattern :
83+ if (
84+ pattern == self .subdomain_gateway_pattern
85+ or pattern == self .native_url_pattern
86+ ):
7987 _hash = _hash .lower ()
8088 try :
8189 if get_codec (_hash ).encoding not in ["base32" , "base36" ]:
@@ -152,7 +160,10 @@ def _is_integral_ipns_url(
152160
153161 ipns_id = match ["hash" ]
154162
155- if ipns_id and pattern == self .subdomain_gateway_pattern :
163+ if (ipns_id ) and (
164+ pattern == self .subdomain_gateway_pattern
165+ or pattern == self .native_url_pattern
166+ ):
156167 ipns_id = ipns_id .lower ()
157168
158169 if Validator (ipns_id )._is_cid ():
@@ -163,7 +174,9 @@ def _is_integral_ipns_url(
163174 print (f"Unexpected { type (error )} , { error } " )
164175 return False
165176 try :
166- if "." not in ipns_id and "-" in ipns_id :
177+ if ("." not in ipns_id and "-" in ipns_id ) and (
178+ pattern == self .subdomain_gateway_pattern
179+ ):
167180 ipns_id = (
168181 ipns_id .replace ("--" , "@" ).replace ("-" , "." ).replace ("@" , "-" )
169182 )
@@ -234,3 +247,19 @@ def _id_is_explicit_tld(self, input_string: str) -> bool:
234247 )
235248 hostname = urlparse (f"http://{ input_string } " ).hostname
236249 return bool (re .search (fqdn_with_tld , hostname ))
250+
251+ def _is_native_ipfs_url (self ) -> bool :
252+ """
253+ Returns True if the provided string is a valid IPFS native URL or False otherwise.
254+ """
255+ return self ._is_integral_ipfs_url (
256+ self .native_url_pattern ,
257+ )
258+
259+ def _is_native_ipns_url (self ) -> bool :
260+ """
261+ Returns True if the provided string is a valid IPNS native URL or False otherwise.
262+ """
263+ return self ._is_integral_ipns_url (
264+ self .native_url_pattern ,
265+ )
0 commit comments