@@ -14,24 +14,18 @@ def initialize(app, public_dir=FileUtils.pwd, php_exe='php-cgi', htaccess_enable
14
14
@htaccess_enabled = htaccess_enabled
15
15
end
16
16
17
- # Override so that calls to the directory go to index.php
18
- def call ( env )
19
- path = env [ 'PATH_INFO' ]
20
- path = "/" if path == ""
21
- path = ::File . join path , 'index.php' if
22
- path =~ /\/ $/ || ::File . directory? ( full_path ( path ) )
23
- env [ 'PATH_INFO' ] = path
24
-
25
- super env
26
- end
27
-
28
17
# Override to check for php extension. Still checks if
29
18
# file is in public path and it is a file like superclass.
30
19
def valid? ( path )
31
- fp = full_path path
32
- return false unless fp =~ /\. php/ # Must have php extension somewhere
33
- sp = path_parts ( fp ) [ 0 ]
34
- sp . start_with? ( ::File . expand_path @public_dir ) && ::File . file? ( sp )
20
+ sp = path_parts ( full_path path ) [ 0 ]
21
+
22
+ # Must have a php extension or be a directory
23
+ return false unless
24
+ ( ::File . file? ( sp ) && sp =~ /\. php$/ ) ||
25
+ ::File . directory? ( sp )
26
+
27
+ # Must be in public directory for security
28
+ sp . start_with? ::File . expand_path ( @public_dir )
35
29
end
36
30
37
31
# Monkeys with the arguments so that it actually runs PHP's cgi
@@ -43,6 +37,7 @@ def run(env, path)
43
37
config . collect! { |kv | [ '-d' , kv ] }
44
38
45
39
script , info = *path_parts ( path )
40
+ script = ::File . join script , 'index.php' if ::File . directory? script
46
41
env [ 'SCRIPT_FILENAME' ] = script
47
42
env [ 'SCRIPT_NAME' ] = strip_public script
48
43
env [ 'PATH_INFO' ] = info
@@ -62,6 +57,7 @@ def strip_public(path)
62
57
# path_info part. Returns an array. The first element is the
63
58
# script. The second element is the path info.
64
59
def path_parts ( path )
60
+ return [ path , nil ] unless path =~ /.php/
65
61
script , info = *path . split ( '.php' , 2 )
66
62
script += '.php'
67
63
[ script , info ]
0 commit comments