Skip to content

Commit 1540ceb

Browse files
erikmdOlivierNicole
authored andcommitted
fix(url.ml): Simplify get_fragment as well
and directly use l##.hash; given Firefox' bug https://bugzilla.mozilla.org/show_bug.cgi?id=483304 is closed since 8+ years.
1 parent 09a8700 commit 1540ceb

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

lib/js_of_ocaml/url.ml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -309,18 +309,10 @@ module Current = struct
309309
else l##.search)
310310

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

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

0 commit comments

Comments
 (0)