File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -23,13 +23,14 @@ defmodule Lexical.Path do
23
23
iex> Lexical.Path.parent_path?("/home/user/docs", "/home/user/docs/subdir")
24
24
false
25
25
"""
26
+ def parent_path? ( child_path , parent_path ) when byte_size ( child_path ) < byte_size ( parent_path ) do
27
+ false
28
+ end
29
+
26
30
def parent_path? ( child_path , parent_path ) do
27
31
normalized_child = Path . expand ( child_path )
28
32
normalized_parent = Path . expand ( parent_path )
29
33
30
- child_segments = Path . split ( normalized_child )
31
- parent_segments = Path . split ( normalized_parent )
32
-
33
- Enum . take ( child_segments , length ( parent_segments ) ) == parent_segments
34
+ String . starts_with? ( normalized_child , normalized_parent )
34
35
end
35
36
end
Original file line number Diff line number Diff line change
1
+ defmodule Lexical.PathTest do
2
+ use ExUnit.Case , async: true
3
+
4
+ doctest Lexical.Path
5
+ end
You can’t perform that action at this time.
0 commit comments