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
2323 iex> Lexical.Path.parent_path?("/home/user/docs", "/home/user/docs/subdir")
2424 false
2525 """
26+ def parent_path? ( child_path , parent_path ) when byte_size ( child_path ) < byte_size ( parent_path ) do
27+ false
28+ end
29+
2630 def parent_path? ( child_path , parent_path ) do
2731 normalized_child = Path . expand ( child_path )
2832 normalized_parent = Path . expand ( parent_path )
2933
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 )
3435 end
3536end
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