command-line-arguments icon indicating copy to clipboard operation
command-line-arguments copied to clipboard

support for float type

Open erjoalgo opened this issue 7 years ago • 5 comments

would it be easy to support float types?

erjoalgo avatar May 02 '18 02:05 erjoalgo

Yes. Look at the occurrences of integer in parse.lisp and add proper support for float (by which I hope you mean double-float, not single-float, although, whatever floats your boat).

fare avatar May 02 '18 04:05 fare

Would you like to become the new maintainer?

fare avatar May 02 '18 05:05 fare

I can make a PR for this feature. so far I haven't needed much more than what is provided, but if there are new requests in the future I may be able to take a look. Thanks

erjoalgo avatar May 03 '18 00:05 erjoalgo

One issues with floats is that there is no natural analog of parse-integer to read a float in common lisp. The easiest solution would be to use read-from-string but then you could get people sneaking arbitrary lisp execution into the argument parsing (e.g., --number "(progn #.(run-misc) 0.1234)". For some applications this could be a serious security problem.

Maybe a read-number type (the name of which would document the inherent danger), or a float type which either uses a bespoke float reader (apparently whole packages exist for this) or tries to sanitize the float argument before passing it to read-from-string (feels like something that is easy to get wrong).

eschulte avatar Nov 02 '18 13:11 eschulte

There is a library for parse-number, and you could use uiop:safe-read-from-string to avoid the #. issue.

fare avatar Feb 24 '20 05:02 fare