Bathbot icon indicating copy to clipboard operation
Bathbot copied to clipboard

fix: convert input to lowercase during arg parse

Open dhopcs opened this issue 1 year ago • 3 comments

Fixes #842

dhopcs avatar Sep 03 '24 22:09 dhopcs

Not quite as simple with rust unfortunately 😩 str::to_lowercase allocates a new String which is dropped right after taking its reference and rust doesn't like that.

I'd recommend using the more efficient CowUtils::cow_to_ascii_lowercase to avoid the forced reallocation but it will have the same issue regarding returned references.

To fix that, I recommend not modifying the parse_key method and instead lowercase the key_opt value that results from the parse_key call.

MaxOhn avatar Sep 03 '24 22:09 MaxOhn

Sorry, been writing too much go recently I think - silly error on my part. Just getting back into rust after hyper-focusing go in my career, appreciate you being as friendly as always Max <3

dhopcs avatar Sep 03 '24 23:09 dhopcs

Don't forget to also adjust the parse_any function which handles arguments of the form AR9.3 instead of AR=9.3 😉

Would also appreciate if you add test cases at the bottom regarding lowercasing.

MaxOhn avatar Sep 03 '24 23:09 MaxOhn

Closed in favor of #928

MaxOhn avatar Feb 10 '25 15:02 MaxOhn