factor out glob2re
parent
b941827420
commit
efd5f9ffb3
15
IkiWiki.pm
15
IkiWiki.pm
|
@ -1290,6 +1290,13 @@ sub pagespec_valid ($) { #{{{
|
|||
my $sub=pagespec_translate($spec);
|
||||
return ! $@;
|
||||
} #}}}
|
||||
|
||||
sub glob2re ($) { #{{{
|
||||
my $re=quotemeta(shift);
|
||||
$re=~s/\\\*/.*/g;
|
||||
$re=~s/\\\?/./g;
|
||||
return $re;
|
||||
} #}}}
|
||||
|
||||
package IkiWiki::FailReason;
|
||||
|
||||
|
@ -1337,12 +1344,8 @@ sub match_glob ($$;@) { #{{{
|
|||
$glob="$from/$glob" if length $from;
|
||||
}
|
||||
|
||||
# turn glob into safe regexp
|
||||
$glob=quotemeta($glob);
|
||||
$glob=~s/\\\*/.*/g;
|
||||
$glob=~s/\\\?/./g;
|
||||
|
||||
if ($page=~/^$glob$/i) {
|
||||
my $regexp=glob2re($glob);
|
||||
if ($page=~/^$regexp$/i) {
|
||||
if (! IkiWiki::isinternal($page) || $params{internal}) {
|
||||
return IkiWiki::SuccessReason->new("$glob matches $page");
|
||||
}
|
||||
|
|
|
@ -318,11 +318,7 @@ sub match_mimetype ($$;@) { #{{{
|
|||
$mimetype="unknown";
|
||||
}
|
||||
|
||||
# turn glob into a safe regexp
|
||||
my $regexp=quotemeta($wanted);
|
||||
$regexp=~s/\\\*/.*/g;
|
||||
$regexp=~s/\\\?/./g;
|
||||
|
||||
my $regexp=IkiWiki::glob2re($wanted);
|
||||
if ($mimetype!~/^$regexp$/i) {
|
||||
return IkiWiki::FailReason->new("file MIME type is $mimetype, not $wanted");
|
||||
}
|
||||
|
|
|
@ -253,9 +253,7 @@ sub match { #{{{
|
|||
my $page=shift;
|
||||
|
||||
# turn glob into a safe regexp
|
||||
my $re=quotemeta(shift);
|
||||
$re=~s/\\\*/.*/g;
|
||||
$re=~s/\\\?/./g;
|
||||
my $re=IkiWiki::glob2re(shift);
|
||||
|
||||
my $val;
|
||||
if (exists $pagestate{$page}{meta}{$field}) {
|
||||
|
|
Loading…
Reference in New Issue