File tree 2 files changed +28
-6
lines changed
2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -242,12 +242,16 @@ def _normPyStr(self, text):
242
242
243
243
try :
244
244
byts = socket .inet_pton (socket .AF_INET , valu )
245
- addr = (4 , int .from_bytes (byts , 'big' ))
246
- ipaddr = ipaddress .IPv4Address (addr [1 ])
247
- subs ['version' ] = 4
248
- except OSError as e :
249
- mesg = f'Invalid IP address: { text } '
250
- raise s_exc .BadTypeValu (mesg = mesg ) from None
245
+ except OSError :
246
+ try :
247
+ byts = socket .inet_aton (valu )
248
+ except OSError as e :
249
+ mesg = f'Invalid IP address: { text } '
250
+ raise s_exc .BadTypeValu (mesg = mesg ) from None
251
+
252
+ addr = (4 , int .from_bytes (byts , 'big' ))
253
+ ipaddr = ipaddress .IPv4Address (addr [1 ])
254
+ subs ['version' ] = 4
251
255
252
256
subs ['type' ] = getAddrType (ipaddr )
253
257
Original file line number Diff line number Diff line change @@ -3070,3 +3070,21 @@ async def test_model_inet_service(self):
3070
3070
self .len (1 , await core .nodes ('inet:service:subscription -> inet:service:subscription:level:taxonomy' ))
3071
3071
self .len (1 , await core .nodes ('inet:service:subscription :pay:instrument -> econ:bank:account' ))
3072
3072
self .len (1 , await core .nodes ('inet:service:subscription :subscriber -> inet:service:tenant' ))
3073
+
3074
+ async def test_ipv4_fallback (self ):
3075
+
3076
+ async with self .getTestCore () as core :
3077
+ self .len (1 , await core .nodes ('[inet:ip=192.168.1.1]' ))
3078
+
3079
+ self .len (1 , await core .nodes ('[inet:ip=3.0.000.115]' ))
3080
+ self .len (1 , await core .nodes ('[inet:ip=192.168.001.001]' ))
3081
+ self .len (1 , await core .nodes ('[inet:ip=10.0.0.001]' ))
3082
+
3083
+ with self .raises (s_exc .BadTypeValu ):
3084
+ await core .nodes ('[inet:ip=256.256.256.256]' )
3085
+
3086
+ with self .raises (s_exc .BadTypeValu ):
3087
+ await core .nodes ('[inet:ip=192.168.001.001.001]' )
3088
+
3089
+ with self .raises (s_exc .BadTypeValu ):
3090
+ await core .nodes ('[inet:ip=192.168.001.001.abc]' )
You can’t perform that action at this time.
0 commit comments