Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version_parser: tolerate + in version numbers and never fail #982

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions language-server/etc/version_parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ let is_number x = try let _ = int_of_string x in true with _ -> false ;;
let main () =
let v = Sys.argv.(1) in
let v' = Str.(replace_first (regexp "^v") "" v) in (* v1.20... -> 1.20... *)
let v' = Str.(replace_first (regexp "-.*$") "" v') in (* ...-10-fjdnfs -> ... *)
let v' = Str.(replace_first (regexp "\\(-\\|\\+\\).*$") "" v') in (* ...-10-fjdnfs -> ... *)
let l = String.split_on_char '.' v' in
(* sanitization *)
let l =
match l with
| [_;_;_] as l when List.for_all is_number l -> l
| [_] -> ["99";"99";"99"]
| _ -> Printf.eprintf "version_parser: cannot parse: %s\n" v; exit 1 in
| n1 :: n2 :: n3 :: _ when is_number n1 && is_number n2 && is_number n3 -> [n1;n2;n3]
| [_;_] as l when List.for_all is_number l -> l @ ["0"]
| [_] as l when List.for_all is_number l -> l @ ["0";"0"]
| _ -> ["99";"99";"99"] in
let open Format in
printf "(%a)%!" (pp_print_list ~pp_sep:(fun fmt () -> pp_print_string fmt ", ") pp_print_string) l
;;
Expand Down
Loading