Skip to content

fix(url.ml): set_fragment need not any urlencode #1497

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

Merged
merged 3 commits into from
Nov 11, 2023
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Compiler: fix free variables pass wrt parameters' default value (#1521)
* Compiler: fix free variables for classes
* Compiler: fix internal invariant (continuation)
* Lib: Url.Current.set_fragment need not any urlencode (#1497)

# 5.4.0 (2023-07-06) - Lille

Expand Down
20 changes: 6 additions & 14 deletions lib/js_of_ocaml/url.ml
Original file line number Diff line number Diff line change
Expand Up @@ -309,20 +309,12 @@ module Current = struct
else l##.search)

let get_fragment () =
(* location.hash doesn't have the same behavior depending on the browser
Firefox bug : https://bugzilla.mozilla.org/show_bug.cgi?id=483304 *)
(* let s = Js.to_bytestring (l##hash) in *)
(* if String.length s > 0 && s.[0] = '#' *)
(* then String.sub s 1 (String.length s - 1) *)
(* else s; *)
Js.Opt.case
(l##.href##_match (new%js Js.regExp (Js.string "#(.*)")))
(fun () -> "")
(fun res ->
let res = Js.match_result res in
Js.to_string (Js.Unsafe.get res 1))

let set_fragment s = l##.hash := Js.bytestring (urlencode s)
let s = Js.to_bytestring l##.hash in
if String.length s > 0 && Char.equal s.[0] '#'
then String.sub s 1 (String.length s - 1)
else s

let set_fragment s = l##.hash := Js.bytestring s

let get () = url_of_js_string l##.href

Expand Down