xlcnd / isbnlib

python library to validate, clean, transform and get metadata of ISBN strings (for devs).
Other
229 stars 30 forks source link

`mask` fails for issued ISBN #114

Closed slint closed 2 years ago

slint commented 2 years ago

When trying to mask 9798847781275 an empty string is returned. When debugging the mask call, it seems like the check at https://github.com/xlcnd/isbnlib/blob/af8ee198a801e64fc9f276193ad5e8d1e119932b/isbnlib/_msk.py#L57 might have a faulty boolean check logic, since idx is 0 (i.e. the group is "found" inside ranges) which is "falsy".

Could it be that the condition check should be if idx is not None: instead? Changing this returns 979-8--84778127-5, which looks a bit more correct, but there might be an off-by-one issue that causes the double hyphen.

(I'm sorry if I'm missing some logic part, I tried to look into the data4mask.py format, but I couldn't understand if ranges with 0s are invalid or have some other special meaning).

xlcnd commented 2 years ago

Yes, it is a bug! I will check it soon...

Thanks.

xlcnd commented 2 years ago

I think it works now.