Skip to content

Commit 4bf0033

Browse files
committed
For [GH #171] - Add a workaround for trailing / after index.yatt
1 parent e2ada7f commit 4bf0033

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

Lite/WebMVC0/DirApp.pm

+33-21
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,21 @@ sub prepare_part_handler {
7373
}
7474

7575
if (not defined $type
76-
and $self->{cf_use_subpath} and my $subpath = $prop->{cf_subpath}) {
77-
my $tmpl = $trans->find_file($file) or do {
78-
croak $self->error("No such file: %s", $file);
79-
};
80-
($part, my ($formal, $actual)) = $tmpl->match_subroutes($subpath) or do {
81-
# XXX: Is this secure against XSS? <- how about URI encoding?
82-
# die $self->psgi_error(404, "No such subpath: ". $subpath);
83-
die $self->psgi_error(404, "No such subpath:: ". $subpath
84-
. " in file " . $tmpl->{cf_path});
85-
};
86-
$pkg = $trans->find_product(perl => $tmpl) or do {
87-
croak $self->error("Can't compile template file: %s", $file);
88-
};
89-
90-
$sub = $pkg->can($part->method_name) or do {
91-
croak $self->error("Can't find %s %s for file: %s"
92-
, $part->cget('kind'), $part->public_name, $file);
93-
};
94-
@args = $trans->reorder_cgi_params($part, $con, $actual)
95-
unless $self->{cf_dont_map_args};
96-
76+
and $self->{cf_use_subpath} and $prop->{cf_subpath}
77+
and (my $tmpl, $part, my ($formal, $actual)) = $self->find_subpath_handler(
78+
$trans, $file, $prop->{cf_subpath}
79+
)) {
80+
81+
$pkg = $trans->find_product(perl => $tmpl) or do {
82+
croak $self->error("Can't compile template file: %s", $file);
83+
};
84+
85+
$sub = $pkg->can($part->method_name) or do {
86+
croak $self->error("Can't find %s %s for file: %s"
87+
, $part->cget('kind'), $part->public_name, $file);
88+
};
89+
@args = $trans->reorder_cgi_params($part, $con, $actual)
90+
unless $self->{cf_dont_map_args};
9791
} else {
9892
($part, $sub, $pkg) = $trans->find_part_handler([$file, $type, $item]);
9993

@@ -109,6 +103,24 @@ sub prepare_part_handler {
109103
($part, $sub, $pkg, \@args);
110104
}
111105

106+
sub find_subpath_handler {
107+
(my MY $self, my ($trans, $file, $subpath)) = @_;
108+
109+
my $tmpl = $trans->find_file($file) or do {
110+
croak $self->error("No such file: %s", $file);
111+
};
112+
113+
if (my @found = $tmpl->match_subroutes($subpath)) {
114+
return ($tmpl, @found);
115+
} else {
116+
if ($subpath ne '/') {
117+
die $self->psgi_error(404, "No such subpath:: ". $subpath
118+
. " in file " . $tmpl->{cf_path});
119+
}
120+
}
121+
return;
122+
}
123+
112124
#========================================
113125
# Action handling
114126
#========================================

0 commit comments

Comments
 (0)