From b958c6bedb7fcb8b71221e6895d29468a985dc43 Mon Sep 17 00:00:00 2001
From: Dominique Hazael-Massieux
Date: Tue, 25 Nov 2014 11:53:13 +0100
Subject: [PATCH 1/2] allow to load ignore list from file
---
bin/checklink | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/bin/checklink b/bin/checklink
index f1d692f..de3a537 100755
--- a/bin/checklink
+++ b/bin/checklink
@@ -490,6 +490,8 @@ my %Opts = (
Suppress_All_Redirects => 0,
Suppress_Broken => [],
Suppress_Fragment => [],
+ Ignore_From_File => undef,
+ Ignore_List => [],
Masquerade => 0,
Masquerade_From => '',
Masquerade_To => '',
@@ -601,6 +603,16 @@ if ($Opts{Command_Line}) {
# Transform the parameter into a URI
$uri = &urize($uri);
+
+ # relative fragments in suppress_fragments get prefixed with first url
+ for my $i (0 .. $#{$Opts{Suppress_Fragment}}) {
+ my $url = ${$Opts{Suppress_Fragment}}[$i];
+ if ($url =~ /^#./) {
+ $url = URI->new_abs($url, $uri)->canonical();
+ ${$Opts{Suppress_Fragment}}[$i] = $url;
+ }
+ }
+
$params{uri} = $uri;
&check_uri(\%params, $uri, $check_num, $Opts{Depth}, undef, undef, 1);
$check_num++;
@@ -795,6 +807,7 @@ sub parse_arguments ()
'suppress-all-redirects' => \$Opts{Suppress_All_Redirects},
'suppress-broken=s@' => \@{$Opts{Suppress_Broken}},
'suppress-fragment=s@' => \@{$Opts{Suppress_Fragment}},
+ 'ignore-from-file=s' => \$Opts{Ignore_From_File},
'u|user=s' => \$Opts{User},
'p|password=s' => \$Opts{Password},
't|timeout=i' => \$Opts{Timeout},
@@ -850,6 +863,22 @@ sub parse_arguments ()
$Opts{Depth} = -1 if ($Opts{Depth} == 0 && @locs);
+ # Open ignore files
+ if (defined($Opts{Ignore_From_File})) {
+ open(my $ignore_file, "<", $Opts{Ignore_From_File})
+ or &usage(1, "Can't open ignore file: $Opts{Ignore_From_File}" );
+ while (my $url = <$ignore_file>) {
+ chomp $url;
+ $url = Encode::decode_utf8($url);
+ if ($url !~ /#./) {
+ push(@{$Opts{Ignore_List}}, $url);
+ } else {
+ push(@{$Opts{Suppress_Fragment}}, $url);
+ }
+ }
+ }
+
+
# Precompile/error-check regular expressions.
if (defined($Opts{Exclude})) {
eval { $Opts{Exclude} = qr/$Opts{Exclude}/o; };
@@ -896,7 +925,7 @@ sub parse_arguments ()
}
}
for my $sf_arg (@{$Opts{Suppress_Fragment}}) {
- if ($sf_arg !~ /.#./) {
+ if ($sf_arg !~ /#./) {
&usage(1,
"Bad suppress-fragment argument, should contain \"#\": $sf_arg"
);
@@ -960,6 +989,8 @@ Options:
--suppress-fragment URI Do not report the given broken fragment URI.
A fragment URI contains \"#\". This option may be
specified multiple times.
+ --ignore-from-file FILE Do not report error for URIs listed in FILE (one
+ per line)
-L, --languages LANGS Accept-Language header to send. The special value
'auto' causes autodetection from the environment.
-c, --cookies FILE Use cookies, load/save them in FILE. The special
@@ -1310,7 +1341,8 @@ EOF
my $canon_uri = URI->new($abs_link_uri->canonical());
my $fragment = $canon_uri->fragment(undef);
- if (!defined($Opts{Exclude}) || $canon_uri !~ $Opts{Exclude}) {
+ if ((!defined($Opts{Exclude}) || $canon_uri !~ $Opts{Exclude})
+ && (!grep { $_ eq $canon_uri } @{$Opts{Ignore_List}})) {
if (!exists($links{$canon_uri})) {
my $hostport;
$hostport = $canon_uri->host_port()
From 7a11d72a2223a1cc736503db267eee2e695ded02 Mon Sep 17 00:00:00 2001
From: Dominique Hazael-Massieux
Date: Wed, 26 Nov 2014 08:49:40 +0100
Subject: [PATCH 2/2] document that relative fragments are interpreted with the
first URI as a base
---
bin/checklink | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/bin/checklink b/bin/checklink
index de3a537..205b5f4 100755
--- a/bin/checklink
+++ b/bin/checklink
@@ -988,9 +988,12 @@ Options:
This option may be specified multiple times.
--suppress-fragment URI Do not report the given broken fragment URI.
A fragment URI contains \"#\". This option may be
- specified multiple times.
+ specified multiple times. Note that you may specify
+ a fragment with no scheme or path (e.g.,
+ #myfragment). In this case the fragment will be
+ considered internal to the first URI being checked.
--ignore-from-file FILE Do not report error for URIs listed in FILE (one
- per line)
+ per line).
-L, --languages LANGS Accept-Language header to send. The special value
'auto' causes autodetection from the environment.
-c, --cookies FILE Use cookies, load/save them in FILE. The special