Kaydet (Commit) d739b01b authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Adapt rtl_uriConvertRelToAbs to RFC 3986

...which updates RFC 2396, removes the requirement that the base URI's path
starts with a slash, and clarifies how to treat excess "." and ".." segments.

This nicely allows handling of those odd vnd.sun.star.Package URLs as intended
now, so that making <foo> absolute relative to base URL
<vnd.sun.star.Package:Pictures/bar> yields <vnd.sun.star.Package:Pictures/foo>
instead of provoking a MalformedUriException.

Change-Id: Ice84303a57698a2c05d3a45541fe78b67450fa3c
üst 58f03356
...@@ -294,39 +294,27 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uriDecode( ...@@ -294,39 +294,27 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uriDecode(
rtl_uString ** pResult) rtl_uString ** pResult)
SAL_THROW_EXTERN_C(); SAL_THROW_EXTERN_C();
/** Convert a relative URI reference into an absolute one. /** Convert a relative URI reference into an absolute URI.
A URI reference is a URI plus an optional @<"#" fragment> part. This function uses the strict parser algorithm described in RFC 3986,
section 5.2.
This function uses the algorithm described in RFC 2396, section 5.2, with
the following clarifications: (1) Backwards-compatible relative URIs
starting with a scheme component (see RFC 2396, section 5.2, step 3) are not
supported. (2) Segments "." and ".." within the path of the base URI are
not considered special, RFC 2396 seems a bit unlcear about that point.
(3) Erroneous excess segments ".." within the path of the relative URI (if
it is indeed relative) are left intact, as the examples in RFC 2396,
section C.2, suggest. (4) If the relative URI is a reference to the
"current document," the "current document" is taken to be the base URI.
This function signals exceptions by returning false and letting pException This function signals exceptions by returning false and letting pException
point to a message explaining the exception. point to a message explaining the exception.
@param pBaseUriRef @param pBaseUriRef
An absolute, hierarchical URI reference that serves as the base URI. If it An absolute URI that serves as the base URI. If it has to be inspected
has to be inspected (i.e., pRelUriRef is not an absolute URI already), and (i.e., pRelUriRef is not an absolute URI already), and it is not an absolute
if it either is not an absolute URI (i.e., does not begin with a URI (i.e., does not begin with a @<scheme ":"> part), an exception will be
@<scheme ":"> part) or has a path that is non-empty but does not start signaled.
with "/", an exception will be signaled.
@param pRelUriRef @param pRelUriRef
An URI reference that may be either absolute or relative. If it is An URI reference that may be either absolute or relative. If it is
absolute, it will be returned unmodified (and it need not be hierarchical absolute, it will be returned unmodified.
then).
@param pResult @param pResult
Returns an absolute URI reference. Must itself not be null, and must point Returns an absolute URI. Must itself not be null, and must point to either
to either null or a valid string. If an exception is signalled, it is left null or a valid string. If an exception is signalled, it is left unchanged.
unchanged.
@param pException @param pException
Returns an explanatory message in case an exception is signalled. Must Returns an explanatory message in case an exception is signalled. Must
......
...@@ -279,14 +279,14 @@ void Test::test_Uri() { ...@@ -279,14 +279,14 @@ void Test::test_Uri() {
char const * pAbs; char const * pAbs;
}; };
static RelToAbsTest const aRelToAbsTest[] static RelToAbsTest const aRelToAbsTest[]
= { // The following tests are taken from RFC 2396: = { // The following tests are taken from RFC 3986:
{ "http://a/b/c/d;p?q", "g:h", "g:h" }, { "http://a/b/c/d;p?q", "g:h", "g:h" },
{ "http://a/b/c/d;p?q", "g", "http://a/b/c/g" }, { "http://a/b/c/d;p?q", "g", "http://a/b/c/g" },
{ "http://a/b/c/d;p?q", "./g", "http://a/b/c/g" }, { "http://a/b/c/d;p?q", "./g", "http://a/b/c/g" },
{ "http://a/b/c/d;p?q", "g/", "http://a/b/c/g/" }, { "http://a/b/c/d;p?q", "g/", "http://a/b/c/g/" },
{ "http://a/b/c/d;p?q", "/g", "http://a/g" }, { "http://a/b/c/d;p?q", "/g", "http://a/g" },
{ "http://a/b/c/d;p?q", "//g", "http://g" }, { "http://a/b/c/d;p?q", "//g", "http://g" },
{ "http://a/b/c/d;p?q", "?y", "http://a/b/c/?y" }, { "http://a/b/c/d;p?q", "?y", "http://a/b/c/d;p?y" },
{ "http://a/b/c/d;p?q", "g?y", "http://a/b/c/g?y" }, { "http://a/b/c/d;p?q", "g?y", "http://a/b/c/g?y" },
{ "http://a/b/c/d;p?q", "#s", "http://a/b/c/d;p?q#s" }, { "http://a/b/c/d;p?q", "#s", "http://a/b/c/d;p?q#s" },
{ "http://a/b/c/d;p?q", "g#s", "http://a/b/c/g#s" }, { "http://a/b/c/d;p?q", "g#s", "http://a/b/c/g#s" },
...@@ -294,6 +294,7 @@ void Test::test_Uri() { ...@@ -294,6 +294,7 @@ void Test::test_Uri() {
{ "http://a/b/c/d;p?q", ";x", "http://a/b/c/;x" }, { "http://a/b/c/d;p?q", ";x", "http://a/b/c/;x" },
{ "http://a/b/c/d;p?q", "g;x", "http://a/b/c/g;x" }, { "http://a/b/c/d;p?q", "g;x", "http://a/b/c/g;x" },
{ "http://a/b/c/d;p?q", "g;x?y#s", "http://a/b/c/g;x?y#s" }, { "http://a/b/c/d;p?q", "g;x?y#s", "http://a/b/c/g;x?y#s" },
{ "http://a/b/c/d;p?q", "", "http://a/b/c/d;p?q" },
{ "http://a/b/c/d;p?q", ".", "http://a/b/c/" }, { "http://a/b/c/d;p?q", ".", "http://a/b/c/" },
{ "http://a/b/c/d;p?q", "./", "http://a/b/c/" }, { "http://a/b/c/d;p?q", "./", "http://a/b/c/" },
{ "http://a/b/c/d;p?q", "..", "http://a/b/" }, { "http://a/b/c/d;p?q", "..", "http://a/b/" },
...@@ -302,11 +303,10 @@ void Test::test_Uri() { ...@@ -302,11 +303,10 @@ void Test::test_Uri() {
{ "http://a/b/c/d;p?q", "../..", "http://a/" }, { "http://a/b/c/d;p?q", "../..", "http://a/" },
{ "http://a/b/c/d;p?q", "../../", "http://a/" }, { "http://a/b/c/d;p?q", "../../", "http://a/" },
{ "http://a/b/c/d;p?q", "../../g", "http://a/g" }, { "http://a/b/c/d;p?q", "../../g", "http://a/g" },
{ "http://a/b/c/d;p?q", "", "http://a/b/c/d;p?q" }, { "http://a/b/c/d;p?q", "../../../g", "http://a/g" },
{ "http://a/b/c/d;p?q", "../../../g", "http://a/../g" }, { "http://a/b/c/d;p?q", "../../../../g", "http://a/g" },
{ "http://a/b/c/d;p?q", "../../../../g", "http://a/../../g" }, { "http://a/b/c/d;p?q", "/./g", "http://a/g" },
{ "http://a/b/c/d;p?q", "/./g", "http://a/./g" }, { "http://a/b/c/d;p?q", "/../g", "http://a/g" },
{ "http://a/b/c/d;p?q", "/../g", "http://a/../g" },
{ "http://a/b/c/d;p?q", "g.", "http://a/b/c/g." }, { "http://a/b/c/d;p?q", "g.", "http://a/b/c/g." },
{ "http://a/b/c/d;p?q", ".g", "http://a/b/c/.g" }, { "http://a/b/c/d;p?q", ".g", "http://a/b/c/.g" },
{ "http://a/b/c/d;p?q", "g..", "http://a/b/c/g.." }, { "http://a/b/c/d;p?q", "g..", "http://a/b/c/g.." },
...@@ -322,13 +322,15 @@ void Test::test_Uri() { ...@@ -322,13 +322,15 @@ void Test::test_Uri() {
{ "http://a/b/c/d;p?q", "g#s/./x", "http://a/b/c/g#s/./x" }, { "http://a/b/c/d;p?q", "g#s/./x", "http://a/b/c/g#s/./x" },
{ "http://a/b/c/d;p?q", "g#s/../x", "http://a/b/c/g#s/../x" }, { "http://a/b/c/d;p?q", "g#s/../x", "http://a/b/c/g#s/../x" },
{ "http://a/b/c/d;p?q", "http:g", "http:g" }, { "http://a/b/c/d;p?q", "http:g", "http:g" },
{ "http!://a/b/c/d;p?q", "g:h", "g:h" }, { "http!://a/b/c/d;p?q", "g:h", "g:h" },
{ "http!://a/b/c/d;p?q", "g", 0 }, { "http!://a/b/c/d;p?q", "g", 0 },
{ "http:b/c/d;p?q", "g:h", "g:h" }, { "http:b/c/d;p?q", "g:h", "g:h" },
{ "http:b/c/d;p?q", "g", 0 }, { "http:b/c/d;p?q", "g", "http:b/c/g" },
{ "http://a/b/../", "../c", "http://a/b/../../c" }, { "http://a/b/../", "../c", "http://a/c" },
{ "http://a/b/..", "../c", "http://a/c" }, { "http://a/b/..", "../c", "http://a/c" },
{ "http://a/./b/", ".././.././../c", "http://a/./../../c" } }; { "http://a/./b/", ".././.././../c", "http://a/c" },
{ "http://a", "b", "http://a/b" } };
for (std::size_t i = 0; i < sizeof aRelToAbsTest / sizeof (RelToAbsTest); ++i) for (std::size_t i = 0; i < sizeof aRelToAbsTest / sizeof (RelToAbsTest); ++i)
{ {
rtl::OUString aAbs; rtl::OUString aAbs;
......
This diff is collapsed.
...@@ -238,11 +238,7 @@ namespace svgio ...@@ -238,11 +238,7 @@ namespace svgio
try { try {
aAbsUrl = rtl::Uri::convertRelToAbs(rPath, maUrl); aAbsUrl = rtl::Uri::convertRelToAbs(rPath, maUrl);
} catch (rtl::MalformedUriException & e) { } catch (rtl::MalformedUriException & e) {
// Happens for the odd rPath = SAL_WARN(
// "vnd.sun.star.Package:Pictures/..." scheme using
// path components not starting with a slash by mis-
// design:
SAL_INFO(
"svg", "svg",
"caught rtl::MalformedUriException \"" "caught rtl::MalformedUriException \""
<< e.getMessage() << "\""); << e.getMessage() << "\"");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment