diff options
author | Stephan Bergmann <sb@openoffice.org> | 2001-08-21 13:51:28 +0000 |
---|---|---|
committer | Stephan Bergmann <sb@openoffice.org> | 2001-08-21 13:51:28 +0000 |
commit | 1f8b28910e880b2b7632e948766225065733e119 (patch) | |
tree | 69158b655a2599e94bd75e1eeab965b8770fcc34 /tools | |
parent | 14f30f3bfef5d020ec9a12a1e382029865e281b5 (diff) |
#85453# Improved convertAbsToRel() for non-DOS file URLs.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/source/fsys/urlobj.cxx | 37 | ||||
-rw-r--r-- | tools/workben/urltest.cxx | 148 |
2 files changed, 158 insertions, 27 deletions
diff --git a/tools/source/fsys/urlobj.cxx b/tools/source/fsys/urlobj.cxx index a3c1e1c6b8ce..a7db546a9ffc 100644 --- a/tools/source/fsys/urlobj.cxx +++ b/tools/source/fsys/urlobj.cxx @@ -2,9 +2,9 @@ * * $RCSfile: urlobj.cxx,v $ * - * $Revision: 1.19 $ + * $Revision: 1.20 $ * - * last change: $Author: sb $ $Date: 2001-08-09 08:34:15 $ + * last change: $Author: sb $ $Date: 2001-08-21 14:50:50 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -1820,10 +1820,13 @@ bool INetURLObject::convertAbsToRel(UniString const & rTheAbsURIRef, } xub_StrLen nMatch = pSlash - pBasePathBegin; - // For file URLs, if the common prefix of the two paths is only "/" (which - // covers different DOS volumes like "/a:" and "/b:"), the subject is not - // made relative (it could be, but some people don't like that): - if (m_eScheme == INET_PROT_FILE && nMatch <= 1) + // If the two URLs are DOS file URLs starting with different volumes + // (e.g., file:///a:/... and file:///b:/...), the subject is not made + // relative (it could be, but some people do not like that): + if (m_eScheme == INET_PROT_FILE + && nMatch <= 1 + && hasDosVolume(eStyle) + && aSubject.hasDosVolume(eStyle)) //TODO! ok to use eStyle for these? { rTheRelURIRef = aSubject.GetMainURL(eDecodeMechanism, eCharset); return false; @@ -2990,6 +2993,18 @@ INetURLObject::FTPType INetURLObject::getFTPType() const } //============================================================================ +bool INetURLObject::hasDosVolume(FSysStyle eStyle) const +{ + sal_Unicode const * p = m_aAbsURIRef.GetBuffer() + m_aPath.getBegin(); + return (eStyle & FSYS_DOS) != 0 + && m_aPath.getLength() >= 3 + && p[0] == '/' + && INetMIME::isAlpha(p[1]) + && p[2] == ':' + && (m_aPath.getLength() == 3 || p[3] == '/'); +} + +//============================================================================ sal_uInt32 INetURLObject::getIMAPUID() const { if (m_eScheme == INET_PROT_IMAP @@ -4601,18 +4616,12 @@ UniString INetURLObject::getFSysPath(FSysStyle eStyle, + (eStyle & FSYS_MAC ? 1 : 0) > 1) { - sal_Unicode const * p = m_aAbsURIRef.GetBuffer() + m_aPath.getBegin(); eStyle = eStyle & FSYS_VOS && m_aHost.isPresent() && m_aHost.getLength() > 0 ? FSYS_VOS : - eStyle & FSYS_DOS - && (!m_aHost.isPresent() || m_aHost.getLength() == 0) - && m_aPath.getLength() >= 3 - && p[0] == '/' - && INetMIME::isAlpha(p[1]) - && p[2] == ':' - && (m_aPath.getLength() == 3 || p[3] == '/') ? + hasDosVolume(eStyle) + && (!m_aHost.isPresent() || m_aHost.getLength() == 0) ? FSYS_DOS : eStyle & FSYS_UNX && (!m_aHost.isPresent() || m_aHost.getLength() == 0) ? diff --git a/tools/workben/urltest.cxx b/tools/workben/urltest.cxx index 35bd1615c5be..40a6585e9e9a 100644 --- a/tools/workben/urltest.cxx +++ b/tools/workben/urltest.cxx @@ -2,9 +2,9 @@ * * $RCSfile: urltest.cxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: sb $ $Date: 2001-08-09 08:34:57 $ + * last change: $Author: sb $ $Date: 2001-08-21 14:51:28 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -59,15 +59,40 @@ * ************************************************************************/ -#include <cstddef> -#include <cstdio> -#include <cstdlib> - #ifndef TOOLS_INETMIME_HXX -#include <inetmime.hxx> +#include "inetmime.hxx" #endif #ifndef _URLOBJ_HXX -#include <urlobj.hxx> +#include "urlobj.hxx" +#endif + +#ifndef _RTL_STRING_H_ +#include "rtl/string.h" +#endif +#ifndef _RTL_STRING_HXX_ +#include "rtl/string.hxx" +#endif +#ifndef _RTL_TEXTENC_H +#include "rtl/textenc.h" +#endif +#ifndef _RTL_USTRING_H_ +#include "rtl/ustring.h" +#endif +#ifndef _RTL_USTRING_HXX_ +#include "rtl/ustring.hxx" +#endif + +#ifndef INCLUDED_CSTDDEF +#include <cstddef> +#define INCLUDED_CSTDDEF +#endif +#ifndef INCLUDED_CSTDLIB +#include <cstdlib> +#define INCLUDED_CSTDLIB +#endif +#ifndef INCLUDED_STDIO_H +#include <stdio.h> +#define INCLUDED_STDIO_H #endif //============================================================================ @@ -85,11 +110,11 @@ struct RelToAbsTest }; //============================================================================ -bool testRelToAbs(RelToAbsTest const * pTest, size_t nSize) +bool testRelToAbs(RelToAbsTest const * pTest, std::size_t nSize) { bool bSuccess = true; INetURLObject aBase; - for (size_t i = 0; i < nSize; ++i) + for (std::size_t i = 0; i < nSize; ++i) { if (pTest[i].m_pBase) { @@ -157,11 +182,11 @@ inline sal_Char const * toString(INetURLObject::FSysStyle eStyle) } //============================================================================ -bool testSetFSys(SetFSysTest const * pTest, size_t nSize) +bool testSetFSys(SetFSysTest const * pTest, std::size_t nSize) { bool bSuccess = true; String aPath; - for (size_t i = 0; i < nSize; ++i) + for (std::size_t i = 0; i < nSize; ++i) { if (pTest[i].m_pPath) aPath = String::CreateFromAscii(pTest[i].m_pPath); @@ -863,7 +888,7 @@ main() } } - if (true) + if (false) { abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "file:///")))); @@ -889,5 +914,102 @@ main() "file:///abcdef/def")))); } + if (true) + { + { + rtl::OUString + aBase(RTL_CONSTASCII_USTRINGPARAM("file:///a:/b/c")); + rtl::OUString aAbs(RTL_CONSTASCII_USTRINGPARAM("file:///a:/d/e")); + rtl::OUString aRel(INetURLObject::GetRelURL(aBase, aAbs)); + if (!aRel.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("../d/e"))) + { + printf("BAD GetRelURL(%s, %s) = %s\n", + rtl::OUStringToOString(aBase, RTL_TEXTENCODING_UTF8). + getStr(), + rtl::OUStringToOString(aAbs, RTL_TEXTENCODING_UTF8). + getStr(), + rtl::OUStringToOString(aRel, RTL_TEXTENCODING_UTF8). + getStr()); + bSuccess = false; + } + } + { + rtl::OUString + aBase(RTL_CONSTASCII_USTRINGPARAM("file:///a:/b/c")); + rtl::OUString aAbs(RTL_CONSTASCII_USTRINGPARAM("file:///d:/e/f")); + rtl::OUString aRel(INetURLObject::GetRelURL(aBase, aAbs)); + if (aRel != aAbs) + { + printf("BAD GetRelURL(%s, %s) = %s\n", + rtl::OUStringToOString(aBase, RTL_TEXTENCODING_UTF8). + getStr(), + rtl::OUStringToOString(aAbs, RTL_TEXTENCODING_UTF8). + getStr(), + rtl::OUStringToOString(aRel, RTL_TEXTENCODING_UTF8). + getStr()); + bSuccess = false; + } + } + { + rtl::OUString + aBase(RTL_CONSTASCII_USTRINGPARAM("file:///a:/b/c")); + rtl::OUString aAbs(RTL_CONSTASCII_USTRINGPARAM("file:///d/e/f")); + rtl::OUString aRel(INetURLObject::GetRelURL(aBase, aAbs)); + if (!aRel.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("../../d/e/f"))) + { + printf("BAD GetRelURL(%s, %s) = %s\n", + rtl::OUStringToOString(aBase, RTL_TEXTENCODING_UTF8). + getStr(), + rtl::OUStringToOString(aAbs, RTL_TEXTENCODING_UTF8). + getStr(), + rtl::OUStringToOString(aRel, RTL_TEXTENCODING_UTF8). + getStr()); + bSuccess = false; + } + } + { + rtl::OUString + aBase(RTL_CONSTASCII_USTRINGPARAM("file:///a:/b/c")); + rtl::OUString aAbs(RTL_CONSTASCII_USTRINGPARAM("file:///d:/e/f")); + rtl::OUString + aRel(INetURLObject::GetRelURL(aBase, + aAbs, + INetURLObject::WAS_ENCODED, + INetURLObject::DECODE_TO_IURI, + RTL_TEXTENCODING_UTF8, + INetURLObject::FSYS_UNX)); + if (!aRel.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM( + "../../d:/e/f"))) + { + printf("BAD GetRelURL(%s, %s) = %s\n", + rtl::OUStringToOString(aBase, RTL_TEXTENCODING_UTF8). + getStr(), + rtl::OUStringToOString(aAbs, RTL_TEXTENCODING_UTF8). + getStr(), + rtl::OUStringToOString(aRel, RTL_TEXTENCODING_UTF8). + getStr()); + bSuccess = false; + } + } + { + rtl::OUString + aBase(RTL_CONSTASCII_USTRINGPARAM("file:///test.html")); + rtl::OUString + aAbs(RTL_CONSTASCII_USTRINGPARAM("/images/myimage.gif")); + rtl::OUString aRel(INetURLObject::GetRelURL(aBase, aAbs)); + if (aRel != aAbs) + { + printf("BAD GetRelURL(%s, %s) = %s\n", + rtl::OUStringToOString(aBase, RTL_TEXTENCODING_UTF8). + getStr(), + rtl::OUStringToOString(aAbs, RTL_TEXTENCODING_UTF8). + getStr(), + rtl::OUStringToOString(aRel, RTL_TEXTENCODING_UTF8). + getStr()); + bSuccess = false; + } + } + } + return bSuccess ? EXIT_SUCCESS : EXIT_FAILURE; } |