Skip to content

Commit

Permalink
Path.Local: backslashes are not canonical on Windows (#4745)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojb authored Jun 18, 2021
1 parent 7310d10 commit 904cbe5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ Unreleased

- Handle renaming of `coq.kernel` library to `coq-core.kernel` in Coq 8.14 (#4713, @proux01)

- Fix generation of merlin configuration when using `(include_subdirs
unqualified)` on Windows (#4745, @nojb)

2.8.5 (28/03/2021)
------------------

Expand Down
8 changes: 8 additions & 0 deletions otherlibs/stdune-unstable/path.ml
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ end = struct
User_error.raise ?loc:error_loc
[ Pp.textf "path outside the workspace: %s from %s" path (to_string t) ]

(* Check whether a path is in canonical form: no '.' or '..' components, no
repeated '/' components, no backslashes '\\' (on Windows only), and not
ending in a slash '/'. *)

let is_canonicalized =
let rec before_slash s i =
if i < 0 then
Expand All @@ -310,6 +314,7 @@ end = struct
match s.[i] with
| '/' -> false
| '.' -> before_dot_slash s (i - 1)
| '\\' when Sys.win32 -> false
| _ -> in_component s (i - 1)
and before_dot_slash s i =
if i < 0 then
Expand All @@ -318,20 +323,23 @@ end = struct
match s.[i] with
| '/' -> false
| '.' -> before_dot_dot_slash s (i - 1)
| '\\' when Sys.win32 -> false
| _ -> in_component s (i - 1)
and before_dot_dot_slash s i =
if i < 0 then
false
else
match s.[i] with
| '/' -> false
| '\\' when Sys.win32 -> false
| _ -> in_component s (i - 1)
and in_component s i =
if i < 0 then
true
else
match s.[i] with
| '/' -> before_slash s (i - 1)
| '\\' when Sys.win32 -> false
| _ -> in_component s (i - 1)
in
fun s ->
Expand Down

0 comments on commit 904cbe5

Please sign in to comment.