@@ -73,27 +73,21 @@ sub prepare_part_handler {
73
73
}
74
74
75
75
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 };
97
91
} else {
98
92
($part , $sub , $pkg ) = $trans -> find_part_handler([$file , $type , $item ]);
99
93
@@ -109,6 +103,24 @@ sub prepare_part_handler {
109
103
($part , $sub , $pkg , \@args );
110
104
}
111
105
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
+
112
124
# ========================================
113
125
# Action handling
114
126
# ========================================
0 commit comments