mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: fix trailing slash in dir() (#7283)
This commit is contained in:
parent
d785e22a6e
commit
095327134e
@ -651,12 +651,9 @@ pub fn dir(path string) string {
|
|||||||
if path == '' {
|
if path == '' {
|
||||||
return '.'
|
return '.'
|
||||||
}
|
}
|
||||||
mut pos := path.last_index(path_separator) or {
|
pos := path.last_index(path_separator) or {
|
||||||
return '.'
|
return '.'
|
||||||
}
|
}
|
||||||
if path.ends_with(path_separator) {
|
|
||||||
pos--
|
|
||||||
}
|
|
||||||
return path[..pos]
|
return path[..pos]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,8 +440,10 @@ fn test_join() {
|
|||||||
fn test_dir() {
|
fn test_dir() {
|
||||||
$if windows {
|
$if windows {
|
||||||
assert os.dir('C:\\a\\b\\c') == 'C:\\a\\b'
|
assert os.dir('C:\\a\\b\\c') == 'C:\\a\\b'
|
||||||
|
assert os.dir('C:\\a\\b\\') == 'C:\\a\\b'
|
||||||
} $else {
|
} $else {
|
||||||
assert os.dir('/var/tmp/foo') == '/var/tmp'
|
assert os.dir('/var/tmp/foo') == '/var/tmp'
|
||||||
|
assert os.dir('/var/tmp/') == '/var/tmp'
|
||||||
}
|
}
|
||||||
assert os.dir('os') == '.'
|
assert os.dir('os') == '.'
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user