mirror of
https://github.com/curl/curl.git
synced 2026-04-14 18:21:40 +03:00
spacecheck: verify filename lengths and characters
Maximum filename length 64, of which 48 maximum for the filename part.
Allowed characters: `A-Za-z0-9/._-`.
Also:
- rename a file to pass the check.
- init max constants outside the loop.
- minor fix to an error message.
Follow-up to 62d77b12fc #21087
Closes #21095
This commit is contained in:
parent
dc9a03e855
commit
afa71f1a22
3 changed files with 27 additions and 9 deletions
|
|
@ -68,7 +68,7 @@ INTERNALDOCS = \
|
||||||
internals/SCORECARD.md \
|
internals/SCORECARD.md \
|
||||||
internals/SPLAY.md \
|
internals/SPLAY.md \
|
||||||
internals/STRPARSE.md \
|
internals/STRPARSE.md \
|
||||||
internals/THRDPOOL+QUEUE.md \
|
internals/THRDPOOL-AND-QUEUE.md \
|
||||||
internals/TIME-KEEPING.md \
|
internals/TIME-KEEPING.md \
|
||||||
internals/TLS-SESSIONS.md \
|
internals/TLS-SESSIONS.md \
|
||||||
internals/UINT_SETS.md \
|
internals/UINT_SETS.md \
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
|
use File::Basename;
|
||||||
|
|
||||||
my @tabs = (
|
my @tabs = (
|
||||||
'^m4/zz40-xc-ovr\.m4$',
|
'^m4/zz40-xc-ovr\.m4$',
|
||||||
'Makefile\.(am|example)$',
|
'Makefile\.(am|example)$',
|
||||||
|
|
@ -104,18 +106,36 @@ sub eol_detect {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $max_repeat_space = 79;
|
||||||
|
my $max_line_len = 192;
|
||||||
|
my $max_path_len = 64;
|
||||||
|
my $max_filename_len = 48;
|
||||||
|
|
||||||
my $issues = 0;
|
my $issues = 0;
|
||||||
|
|
||||||
open(my $git_ls_files, '-|', 'git', 'ls-files') or die "Failed running git ls-files: $!";
|
open(my $git_ls_files, '-|', 'git', 'ls-files') or die "Failed running git ls-files: $!";
|
||||||
while(my $filename = <$git_ls_files>) {
|
while(my $filename = <$git_ls_files>) {
|
||||||
chomp $filename;
|
chomp $filename;
|
||||||
|
|
||||||
|
my @err = ();
|
||||||
|
|
||||||
|
if(length($filename) > $max_path_len) {
|
||||||
|
push @err, sprintf('long (%d > %d) path', length($filename), $max_path_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
my $bn = basename($filename);
|
||||||
|
if(length($bn) > $max_filename_len) {
|
||||||
|
push @err, sprintf('long (%d > %d) filename', length($bn), $max_filename_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($filename !~ /^[A-Za-z0-9\/._-]+$/) {
|
||||||
|
push @err, sprintf("filename contains character(s) outside [A-Za-z0-9/._-]");
|
||||||
|
}
|
||||||
|
|
||||||
open(my $fh, '<', $filename) or die "Cannot open '$filename': $!";
|
open(my $fh, '<', $filename) or die "Cannot open '$filename': $!";
|
||||||
my $content = do { local $/; <$fh> };
|
my $content = do { local $/; <$fh> };
|
||||||
close $fh;
|
close $fh;
|
||||||
|
|
||||||
my @err = ();
|
|
||||||
|
|
||||||
if(!fn_match($filename, @tabs) &&
|
if(!fn_match($filename, @tabs) &&
|
||||||
$content =~ /\t/) {
|
$content =~ /\t/) {
|
||||||
push @err, 'content: has tab';
|
push @err, 'content: has tab';
|
||||||
|
|
@ -181,21 +201,19 @@ while(my $filename = <$git_ls_files>) {
|
||||||
|
|
||||||
if(!fn_match($filename, @longline)) {
|
if(!fn_match($filename, @longline)) {
|
||||||
my $line = 0;
|
my $line = 0;
|
||||||
my $max = 192;
|
|
||||||
for my $l (split(/\n/, $content)) {
|
for my $l (split(/\n/, $content)) {
|
||||||
$line++;
|
$line++;
|
||||||
if(length($l) > $max) {
|
if(length($l) > $max_line_len) {
|
||||||
push @err, sprintf('line %d: long (%d > %d) line', $line, length($l), $max);
|
push @err, sprintf('line %d: long (%d > %d) line', $line, length($l), $max_line_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $line = 0;
|
my $line = 0;
|
||||||
my $max = 79;
|
|
||||||
for my $l (split(/\n/, $content)) {
|
for my $l (split(/\n/, $content)) {
|
||||||
$line++;
|
$line++;
|
||||||
if($l =~ /( {$max,})/) {
|
if($l =~ /( {$max_repeat_space,})/) {
|
||||||
push @err, sprintf('line %d: repeat spaces (%d > %d)', $line, length($1), $max);
|
push @err, sprintf('line %d: repeat spaces (%d >= %d)', $line, length($1), $max_repeat_space);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue