mgrs icon indicating copy to clipboard operation
mgrs copied to clipboard

mgrs.inverse(uuidString) returns an array of NaN values

Open matthias-ccri opened this issue 3 years ago • 2 comments

Calling mgrs.inverse('1fcd3c38-ef3d-462d-8fd4-6191bde89736') returns [NaN, NaN, NaN, NaN].

The input string is not a mgrs string so it's expected that mgrs would fail to parse it. But could the library fail in a more obvious way, such as returning undefined or throwing an error?

Our company got bitten by this, since we were using mgrs to detect whether a string was mgrs. We have a search field where the user can enter latlon coordinates, mgrs, and place names, and so our code tries to detect whether a string is mgrs. Unfortunately, we considered an array return value to be a successful parse. We now have code to check for the NaNs. Should this failure case be improved?

Thanks.

matthias-ccri avatar Dec 09 '21 19:12 matthias-ccri

Hi, @matthias-ccri . That's a great suggestion! Would you like to work on a contribution and submit a Pull Request? If not, I can try to get to it, but I can't promise that would happen soon.

DanielJDufour avatar Dec 09 '21 19:12 DanielJDufour

If you (or whoever) works on this, please also add a test case to https://github.com/proj4js/mgrs/blob/master/test/test.js

DanielJDufour avatar Dec 09 '21 19:12 DanielJDufour