Skip to content

Commit f38c86e

Browse files
committed
patch 8.0.1352: dead URLs in the help go unnoticed
Problem: Dead URLs in the help go unnoticed. Solution: Add a script to check URLs in the help files. (Christian Brabandt)
1 parent bdb8139 commit f38c86e

3 files changed

Lines changed: 71 additions & 0 deletions

File tree

Filelist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ RT_ALL = \
584584
runtime/doc/*.txt \
585585
runtime/doc/Makefile \
586586
runtime/doc/doctags.c \
587+
runtime/doc/test_urls.vim \
587588
runtime/doc/vim.1 \
588589
runtime/doc/evim.1 \
589590
runtime/doc/vimdiff.1 \

runtime/doc/test_urls.vim

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
" Test for URLs in help documents.
2+
"
3+
" Opens a new window with all found URLS followed by return code from curl
4+
" (anything other than 0 means unreachable)
5+
"
6+
" Written by Christian Brabandt.
7+
8+
func Test_check_URLs()
9+
if has("win32")
10+
echoerr "Doesn't work on MS-Windows"
11+
return
12+
endif
13+
if executable('curl')
14+
" Note: does not follow redirects!
15+
let s:command = 'curl --silent --fail --output /dev/null --head '
16+
elseif executable('wget')
17+
" Note: only allow a couple of redirects
18+
let s:command = 'wget --quiet -S --spider --max-redirect=2 --timeout=5 --tries=2 -O /dev/null '
19+
else
20+
echoerr 'Only works when "curl" or "wget" is available'
21+
return
22+
endif
23+
24+
let pat='\(https\?\|ftp\)://[^\t* ]\+'
25+
exe 'helpgrep' pat
26+
helpclose
27+
28+
let urls = map(getqflist(), 'v:val.text')
29+
" do not use submatch(1)!
30+
let urls = map(urls, {key, val -> matchstr(val, pat)})
31+
" remove examples like user@host (invalid urls)
32+
let urls = filter(urls, 'v:val !~ "@"')
33+
" Remove example URLs which are invalid
34+
let urls = filter(urls, {key, val -> val !~ '\<\(\(my\|some\)\?host\|machine\|hostname\|file\)\>'})
35+
new
36+
put =urls
37+
" remove some more invalid items
38+
" empty lines
39+
v/./d
40+
" remove # anchors
41+
%s/#.*$//e
42+
" remove trailing stuff (parenthesis, dot, comma, quotes), but only for HTTP
43+
" links
44+
g/^h/s#[.,)'"/>][:.]\?$##
45+
g#^[hf]t\?tp:/\(/\?\.*\)$#d
46+
silent! g/ftp://,$/d
47+
silent! g/=$/d
48+
let a = getline(1,'$')
49+
let a = uniq(sort(a))
50+
%d
51+
call setline(1, a)
52+
53+
" Do the testing.
54+
set nomore
55+
%s/.*/\=TestURL(submatch(0))/
56+
57+
" highlight the failures
58+
/.* \([0-9]*[1-9]\|[0-9]\{2,}\)$
59+
endfunc
60+
61+
func TestURL(url)
62+
" Relies on the return code to determine whether a page is valid
63+
echom printf("Testing URL: %d/%d %s", line('.'), line('$'), a:url)
64+
call system(s:command . shellescape(a:url))
65+
return printf("%s %d", a:url, v:shell_error)
66+
endfunc
67+
68+
call Test_check_URLs()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ static char *(features[]) =
771771

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1352,
774776
/**/
775777
1351,
776778
/**/

0 commit comments

Comments
 (0)