ocsigen / js_of_ocaml

Compiler from OCaml to Javascript.
http://ocsigen.org/js_of_ocaml/
Other
947 stars 185 forks source link

[BUG] caml_float_of_string's handling of whitespace doesn't match Stdlib #1518

Open tpetr opened 10 months ago

tpetr commented 10 months ago

Describe the bug jsoo's implementation of caml_float_of_string doesn't match Stdlib's handling of whitespace: jsoo allows trailing whitespace while regular ocaml does not

jsoo toplevel:

        OCaml version 5.0.0
     Compiled with Js_of_ocaml version 5.4.0+e2e1f3d
float_of_string "3.14";;
- : float = 3.14
float_of_string " 3.14";;
- : float = 3.14
float_of_string "3. 14";;
Exception: Failure "float_of_string".
float_of_string "3.14 ";;
- : float = 3.14

ocaml toplevel:

OCaml version 4.14.0
Enter #help;; for help.

Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable threads

# float_of_string "3.14";;
- : float = 3.14
# float_of_string " 3.14";;
- : float = 3.14
# float_of_string "3. 14";;
Exception: Failure "float_of_string".
# float_of_string "3.14 ";;
Exception: Failure "float_of_string".

(tl;dr float_of_string "3.14 " fails in regular ocaml but not jsoo)

Expected behavior Trailing whitespace passed to float_of_string would raise an exception.

Versions ocamlc 4.14 jsoo 5.4.0

(NOTE: this is an extremely low-priority bug, but wanted to flag it because we stumbled across it in semgrep.js: https://github.com/returntocorp/semgrep/pull/8902/files#diff-e2f964d2fdf546821a6fcd6c642efc8e962a8972a1731b8196d36ef2e0aa621dR44-R47)

hhugo commented 10 months ago

Would you be able to contribute a PR ?