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

404 on illegal package name #2682

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion src/ocamlorg_package/lib/ocamlorg_package.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
module Import = Import
open Import
module Name = OpamPackage.Name

module Name = struct
include OpamPackage.Name

let of_string_opt str = try Some (of_string str) with _ -> None
end

module Version = OpamPackage.Version
module Info = Info
module Statistics = Packages_stats
Expand Down
1 change: 1 addition & 0 deletions src/ocamlorg_package/lib/ocamlorg_package.mli
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Name : sig
val compare : t -> t -> int
val to_string : t -> string
val of_string : string -> t
val of_string_opt : string -> t option

module Map : OpamStd.MAP with type key := t
end
Expand Down
21 changes: 16 additions & 5 deletions src/ocamlorg_web/lib/handler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ let is_ocaml_yet t id req =
category.packages)
|> List.filter_map (fun (p : Data.Is_ocaml_yet.package) ->
let name = Ocamlorg_package.Name.of_string p.name in
(* FIXME: Failure *)
match Ocamlorg_package.get_latest t name with
| Some x -> Some x
| None ->
Expand Down Expand Up @@ -913,7 +914,9 @@ let packages_autocomplete_fragment t req =
| _ -> Dream.html ""

let package_overview t kind req =
let name = Ocamlorg_package.Name.of_string @@ Dream.param req "name" in
let</>? name =
Ocamlorg_package.Name.of_string_opt @@ Dream.param req "name"
in
let version_from_url = Dream.param req "version" in
let</>? package, frontend_package =
Package_helper.of_name_version t name version_from_url
Expand Down Expand Up @@ -1043,15 +1046,19 @@ let package_overview t kind req =
~search_index_digest ~toc ~deps_and_conflicts frontend_package)

let package_versions t _kind req =
let name = Ocamlorg_package.Name.of_string @@ Dream.param req "name" in
let</>? name =
Ocamlorg_package.Name.of_string_opt @@ Dream.param req "name"
in
let version_from_url = Dream.param req "version" in
let</>? _package, frontend_package =
Package_helper.of_name_version t name version_from_url
in
Dream.html (Ocamlorg_frontend.package_versions frontend_package)

let package_documentation t kind req =
let name = Ocamlorg_package.Name.of_string @@ Dream.param req "name" in
let</>? name =
Ocamlorg_package.Name.of_string_opt @@ Dream.param req "name"
in
let version_from_url = Dream.param req "version" in
let</>? package, frontend_package =
Package_helper.of_name_version t name version_from_url
Expand Down Expand Up @@ -1185,7 +1192,9 @@ let package_documentation t kind req =
~content:doc.content frontend_package)

let package_file t kind req =
let name = Ocamlorg_package.Name.of_string @@ Dream.param req "name" in
let</>? name =
Ocamlorg_package.Name.of_string_opt @@ Dream.param req "name"
in
let version_from_url = Dream.param req "version" in
let</>? package, frontend_package =
Package_helper.of_name_version t name version_from_url
Expand All @@ -1210,7 +1219,9 @@ let package_file t kind req =
~search_index_digest ~content_title:path ~toc frontend_package)

let package_search_index t kind req =
let name = Ocamlorg_package.Name.of_string @@ Dream.param req "name" in
let</>? name =
Ocamlorg_package.Name.of_string_opt @@ Dream.param req "name"
in
let version_from_url = Dream.param req "version" in
let</>? package, _ = Package_helper.of_name_version t name version_from_url in
let open Lwt.Syntax in
Expand Down
Loading