Fixed handling of paths without leading ..'s, now relative paths starting in the same directory (i.e. subdir/file.dtd) and absolute paths (/art/actors/object.dtd) work as one would think they should

This was SVN commit r635.
This commit is contained in:
Simon Brenner 2004-07-07 01:44:54 +00:00
parent 6b4c07a5a7
commit b5bd1b82ec

View File

@ -115,6 +115,20 @@ InputSource *CVFSEntityResolver::resolveEntity(const XMLCh *const publicId,
char abspath[VFS_MAX_PATH];
const char *end=strchr(m_DocName, '\0');
const char *orgend=end;
if (IS_PATH_SEP(*path))
path++;
else
{
// We know that we have a relative path here:
// - Remove the file name
// - If we have a ../ components - remove them and remove one component
// off the end of the document path for each ../ component
// - prefix of document path + suffix of input path => the VFS path
// Remove the file name
end=prevpathcomp(end, m_DocName);
// Remove one path component for each opening ../ (or ..\)
// Note that this loop will stop when all path components from the
@ -128,15 +142,8 @@ InputSource *CVFSEntityResolver::resolveEntity(const XMLCh *const publicId,
path += 3;
}
// The ../ loop has found opening ../'s
if (path != orgpath)
{
// Remove one more path component
if (end > m_DocName)
end=prevpathcomp(end, m_DocName);
// include one slash from suffix
--path;
// include one slash from prefix
end++;
const ptrdiff_t prefixlen=end-m_DocName;
@ -145,16 +152,19 @@ InputSource *CVFSEntityResolver::resolveEntity(const XMLCh *const publicId,
// strncpy might not have terminated, if path was too long
abspath[VFS_MAX_PATH-1]=0;
char *pos=abspath;
path=abspath;
}
LOG(NORMAL, "EntityResolver: path \"%s\" translated to \"%s\"", orgpath, path);
char *pos=path;
if ((pos=strchr(pos, '\\')) != NULL)
{
LOG(WARNING, "While resolving XML entities for %s: path %s [%s] contains non-portable path separator \\", m_DocName, orgpath, abspath);
LOG(WARNING, "While resolving XML entities for %s: path %s [%s] contains non-portable path separator \\", m_DocName, orgpath, path);
do
*pos='/';
while ((pos=strchr(pos+1, '\\')) != NULL);
}
path=abspath;
}
if (ret->OpenFile(path)!=0)
{