You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, this doesn't work if the dir argument doesn't contain a trailing slash. For example:
common(["/path/to/dir","/path/to/dir/file.txt"]);
returns "/path/to/dir/", and "/path/to/dir/" != "/path/to/dir"
Describe the solution you'd like
If I'm not mistaken, /path/to/dir and /path/to/dir/ both point to the same thing. If so, then wouldn't it make sense to have a function that removes trailing slashes from paths? Maybe normalize() would be a good fit for this.
Describe alternatives you've considered
Add a function to std that performs this exact algorithm
Make common() remove the trailing slash
It seems resolve() also removes trailing slashes, though passing just a single command isn't really documented anywhere (and neither does it contain tests for this case)
The text was updated successfully, but these errors were encountered:
That would work in a scenario where you'd want to see if a file is a direct child of a specific directory. But I'd also want to detect files in subdirectories. I.e.
I agree. I think that resolve('/path/to/dir') and normalize('/path/to/dir') should produce the same output. Also think common should omit trailing slashes as well.
If you look at the Go std library Clean and Dir functions, they explicitly don't return trailing slashes unless it's a root directory. Dir is similar to common in that it still omits the trailing slash even though we know it will always return a directory.
Is your feature request related to a problem? Please describe.
I'm trying to find out if a file is inside a specific directory. My plan was to do it like this:
However, this doesn't work if the
dir
argument doesn't contain a trailing slash. For example:returns
"/path/to/dir/"
, and"/path/to/dir/" != "/path/to/dir"
Describe the solution you'd like
If I'm not mistaken,
/path/to/dir
and/path/to/dir/
both point to the same thing. If so, then wouldn't it make sense to have a function that removes trailing slashes from paths? Maybenormalize()
would be a good fit for this.Describe alternatives you've considered
common()
remove the trailing slashresolve()
also removes trailing slashes, though passing just a single command isn't really documented anywhere (and neither does it contain tests for this case)The text was updated successfully, but these errors were encountered: