Skip to content

Commit

Permalink
fixup! filename: add is_escapable function
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbou committed Sep 8, 2023
1 parent fa30b41 commit f367c6e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
12 changes: 3 additions & 9 deletions src/core/opamFilename.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@
(* *)
(**************************************************************************)

let is_escapable =
let re =
Re.(compile @@ seq [
alt [ char '/'; char '\\'];
str "..";
alt [ char '/'; char '\\']
])
in
fun s -> Re.matches re s <> []
let might_escape path =
List.exists (String.equal Filename.parent_dir_name)
Re.(split (compile (str Filename.dir_sep)) path)

module Base = struct
include OpamStd.AbstractString
Expand Down
4 changes: 2 additions & 2 deletions src/core/opamFilename.mli
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
(** Higher level file and directory name manipulation AND file operations,
wrappers on OpamSystem using the filename type *)

(* Returns [true] if string contains '/../' or '\..\' *)
val is_escapable: string -> bool
(* Returns [true] if string contains '..' between directory separators *)
val might_escape: string -> bool

(** Basenames *)
module Base: sig
Expand Down

0 comments on commit f367c6e

Please sign in to comment.