vdoc: fix infinit recursive calls (fix #24232) (#24274)

This commit is contained in:
kbkpbot 2025-04-21 22:53:23 +08:00 committed by GitHub
parent fd79183122
commit 491a1ac515
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View file

@ -234,7 +234,10 @@ fn (vd &VDoc) get_readme(path string) Readme {
} }
if fname == '' { if fname == '' {
if path.all_after_last(os.path_separator) == 'src' { if path.all_after_last(os.path_separator) == 'src' {
return vd.get_readme(path.all_before_last(os.path_separator)) next_path := path.all_before_last(os.path_separator)
if next_path != '' && path != next_path && os.is_dir(next_path) {
return vd.get_readme(next_path)
}
} }
return Readme{} return Readme{}
} }

View file

@ -4,6 +4,8 @@ module main
import os import os
import arrays import arrays
const vexe_path = @VEXE
const vexe_ = os.quoted_path(vexe_path)
const tpath = os.join_path(os.vtmp_dir(), 'vod_test_module') const tpath = os.join_path(os.vtmp_dir(), 'vod_test_module')
fn testsuite_begin() { fn testsuite_begin() {
@ -104,3 +106,28 @@ fn test_get_module_list() {
// `delta` only contains a `_test.v` file. // `delta` only contains a `_test.v` file.
assert !mod_list.any(it.contains(os.join_path(tpath, 'delta'))) assert !mod_list.any(it.contains(os.join_path(tpath, 'delta')))
} }
fn test_get_readme_md_src() {
// a special testcase for `src` dir get_readme
// https://github.com/vlang/v/issues/24232
os.mkdir('src')!
os.write_file('v.mod', "Module {
name: 'foobar'
description: 'foobar'
version: '0.0.0'
license: 'MIT'
dependencies: []
}
")!
os.write_file('src/foobar.v', 'module foobar
// square calculates the second power of `x`
pub fn square(x int) int {
return x * x
}
')!
res := os.execute_opt('${vexe_} doc -m src/ -v') or { panic(err) }
assert res.exit_code == 0
assert res.output.contains('square')
}