04-17-07 12:12 PM
[ https://issues.apache.org/jira/brow...ls:all-tabpanel ]
Graham Dumpleton closed MODPYTHON-171.
--------------------------------------
> Assignment to req.filename and POSIX style pathnames.
> -----------------------------------------------------
>
> Key: MODPYTHON-171
> URL: https://issues.apache.org/jira/browse/MODPYTHON-171
> Project: mod_python
> Issue Type: Bug
> Components: core
> Affects Versions: 3.2.8
> Reporter: Graham Dumpleton
> Assigned To: Graham Dumpleton
>
> In Apache, all the path names relating to the matched target of a request are deal
t with as POSIX style paths. That is, a forward slash is used as the directory separ
ator even if the platform is Win32. The only real allowance for Win32 stuff is that
dri
ve specifiers may still occur in which case the drive letter is always converted to upper ca
se.
> All the Apache C API functions dealing with manipulation of and specifically gener
ation of modified paths will by default ensure that paths are maintained in this POS
IX style. To have a path be generated in its true native form, you need to provide s
pec
ial flags to functions.
> When an Apache module writer works with paths, they would normally rely on
the default behaviour and so long as they use the functions provided by the
Apache C API, the result will always be consistent.
> Where would all this be a potential issue is where modules set the request_rec->fi
lename attribute, ie., the req.filename attribute of the mod_python request object.
In a C Apache module, as the result is always going to be in the correct form when r
equ
est_rec->filename is modified, everything still comes out okay.
> The problem in mod_python, or more perhaps when using Python, is that all the dire
ctory manipulation routines in os.path as they exist on Win32 platform can generate
paths with back slashes in them. Further, it is often convenient to use __file__ att
rib
ute of modules in some way, which again is going to use back slashes on Win3
2 platform. If the results from either of these is assigned to req.filename,
the result request_rec->filename attribute is no longer going to be in the
POSIX style form which is w
ould normally exist if only the Apache C APIs were used.
> One area where this causes a problem (and which isn't fixed) was described in MODP
YTHON-161, whereby setting req.filename to a path which includes back slashes instea
d of the required POSIX style forward slashes can result in the wrong interpreter be
ing
selected for a subsequent phase if the PythonInterpPerDirectory directive is being used. The
case used for any drive specifier could similarly be a problem.
> Now although Python provides os.path.normpath(), that normalises a path in the nat
ive format. There is no function which can normalise a path and output it in the POS
IX style format. Trying to create a function in Python which does may not yield the
sam
e result as what Apache expects.
> The actual function in Apache which can be used to normalise paths and which outpu
ts the POSIX style path required is apr_filepath_merge(). The question is, should th
is be exposed in some way so that it is useable from mod_python, or for the req.file
nam
e case, should assignment to req.filename automatically trigger normalisatio
n of the path to ensure that it simply just works all the time and isn't dep
endent on a user of mod_python realising they need to normalise it first in
the POSIX style to ensure t
heir code is portable across platforms.
[ Post a follow-up to this message ]
|