1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: fix os.file_ext('/tmp/.gitignore') previously returning '.gitignore' => it now returns '' (#16771)

This commit is contained in:
yuyi 2022-12-26 18:53:38 +08:00 committed by GitHub
parent 64ed007f94
commit 68883fc4d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -209,10 +209,11 @@ pub fn is_dir_empty(path string) bool {
// assert os.file_ext('.ignore_me') == ''
// assert os.file_ext('.') == ''
// ```
pub fn file_ext(path string) string {
if path.len < 3 {
pub fn file_ext(opath string) string {
if opath.len < 3 {
return empty_str
}
path := file_name(opath)
pos := path.last_index(dot_str) or { return empty_str }
if pos + 1 >= path.len || pos == 0 {
return empty_str

View File

@ -599,6 +599,10 @@ fn test_file_ext() {
assert os.file_ext('file...') == ''
assert os.file_ext('.file.') == ''
assert os.file_ext('..file..') == ''
assert os.file_ext('./.git') == ''
assert os.file_ext('./.git/') == ''
assert os.file_ext('\\.git') == ''
assert os.file_ext('\\.git\\') == ''
}
fn test_join() {