File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -173,8 +173,20 @@ pub fn is_dir_empty(path string) bool {
173
173
174
174
// file_ext will return the part after the last occurence of `.` in `path`.
175
175
// The `.` is included.
176
+ // Examples:
177
+ // ```v
178
+ // assert os.file_ext('file.v') == '.v'
179
+ // assert os.file_ext('.ignore_me') == ''
180
+ // assert os.file_ext('.') == ''
181
+ // ```
176
182
pub fn file_ext (path string ) string {
177
- pos := path.last_index ('.' ) or { return '' }
183
+ if path.len < 3 {
184
+ return empty_str
185
+ }
186
+ pos := path.last_index (dot_str) or { return empty_str }
187
+ if pos + 1 > = path.len || pos == 0 {
188
+ return empty_str
189
+ }
178
190
return path[pos..]
179
191
}
180
192
Original file line number Diff line number Diff line change @@ -585,9 +585,19 @@ fn test_is_executable_writable_readable() ? {
585
585
os.rm (file_name) or { panic (err) }
586
586
}
587
587
588
- fn test_ext () {
588
+ fn test_file_ext () {
589
589
assert os.file_ext ('file.v' ) == '.v'
590
+ assert os.file_ext ('file.js.v' ) == '.v'
591
+ assert os.file_ext ('file.ext1.ext2.ext3' ) == '.ext3'
592
+ assert os.file_ext ('.ignore_me.v' ) == '.v'
590
593
assert os.file_ext ('file' ) == ''
594
+ assert os.file_ext ('.git' ) == ''
595
+ assert os.file_ext ('file.' ) == ''
596
+ assert os.file_ext ('.' ) == ''
597
+ assert os.file_ext ('..' ) == ''
598
+ assert os.file_ext ('file...' ) == ''
599
+ assert os.file_ext ('.file.' ) == ''
600
+ assert os.file_ext ('..file..' ) == ''
591
601
}
592
602
593
603
fn test_join () {
You can’t perform that action at this time.
0 commit comments