Bug in declare base-uri
Friday, 23 January 2015 · 5 messages · last reply 18 May 2015
HR
Hans-Juergen Rennau23 Jan 2015 23:09 #
Dear BaseX team,
I think there is a bug in the determination of the static base URI in the special case that a base URI declaration contains a relative URI equal to or starting with "..". Consider this declaration:declare base-uri "..";
The effect should be that relative URIs are resolved against the PARENT directory of the directory containing the query.
If the query is located at, say, file:///a/b/c/query.xq, I would expect the static base-uri to be /a/b/, so that a URI like "abc.xml" would be resolved to file:///a/b/abc.xml. However, the static base URI as determined by BaseX in this case misses the trailing /, it is: file:///a/bThe effect is that a URI like "abc.xml" would be resolved to file:///a/abc.xmlIn other words: URIs are resolved against the "GRAND-PARENT" directory of the query. Final remark: the effect of resolving URIs against the parent directory of the query is achieved by the surprising base URI declaration: declare base-uri ".";
which is not what I would expect.
Conclusion: the way to achieve a resolving of relative URIs against the parent directory of the query should be achieved by the base URI declaration ".." - and no other value.
Kind regards,Hans-Juergen
Full example:Query ( file file:///projects/infospace/pcol/test.xq);
declare base-uri "..";
declare variable $uri external;
string-join((
'query-file: file:///projects/infospace/pcol/test.xq',
concat('static-base-uri: ', static-base-uri()),
concat('resolve-uri("try.xml")=', resolve-uri("try.xml"))
), '
')Output:query-file: file:///projects/infospace/pcol/test.xq static-base-uri: file:///C:/projects/infospace
resolve-uri("try.xml")=file:/C:/projects/try.xml
CG
Christian Grün24 Jan 2015 09:02 #
Hans-Jürgen,
Thanks for the report; I can confirm that the trailing slash is missing in the result. I noticed it's quite a hassle to implement all the XQuery URI resolutions in Java, because Java's default classes do not comply 100% with RFC 3986.
I have added a new GitHub issue [1].
As you seem to have spent some time with the spec, can you possibly tell me how the following URIs should correctly be resolved? I tried some XQuery implementations, they all gave me different results...
declare base-uri "../../../../../../../../../../../..";
static-base-uri()
declare base-uri "C:/";
static-base-uri()
declare base-uri "C:/..";
static-base-uri()Thanks in advance,
Christian
[1] https://github.com/BaseXdb/basex/issues/1062
Quoted text · Hans-Juergen Rennau · 56 lines
On Fri, Jan 23, 2015 at 11:09 PM, Hans-Juergen Rennau <hrennau at yahoo.de> wrote: > Dear BaseX team, > > I think there is a bug in the determination of the static base URI in the > special case that a base URI declaration contains a relative URI equal to or > starting with "..". > > Consider this declaration: > declare base-uri ".."; > > The effect should be that relative URIs are resolved against the PARENT > directory of the directory containing the query. > > If the query is located at, say, file:///a/b/c/query.xq, I would expect the > static base-uri to be /a/b/, so that a URI like "abc.xml" would be resolved > to file:///a/b/abc.xml. > > However, the static base URI as determined by BaseX in this case misses the > trailing /, it is: file:///a/b > The effect is that a URI like "abc.xml" would be resolved to > file:///a/abc.xml > In other words: URIs are resolved against the "GRAND-PARENT" directory of > the query. > > Final remark: the effect of resolving URIs against the parent directory of > the query is achieved by the surprising base URI declaration: > > declare base-uri "."; > > which is not what I would expect. > > Conclusion: the way to achieve a resolving of relative URIs against the > parent directory of the query should be achieved by the base URI declaration > ".." - and no other value. > > Kind regards, > Hans-Juergen > > Full example: > Query ( file file:///projects/infospace/pcol/test.xq); > > declare base-uri ".."; > declare variable $uri external; > > string-join(( > 'query-file: file:///projects/infospace/pcol/test.xq', > concat('static-base-uri: ', static-base-uri()), > concat('resolve-uri("try.xml")=', resolve-uri("try.xml")) > ), '
') > > Output: > query-file: file:///projects/infospace/pcol/test.xq > static-base-uri: file:///C:/projects/infospace > resolve-uri("try.xml")=file:/C:/projects/try.xml > >
HR
Hans-Juergen Rennau26 Jan 2015 22:35 #
Christian,
unfortunately I cannot give the answers to your questions. My attempts to find answers in the spec rather quickly failed. Concerning the first case, the many ".."s, supposedly more of them than the base URI has path steps, my feeling is that there is no sensible alternative to resolving the URI to "file:///" (or "file:/" or "file://", I wonder...) - what else could possibly be the intention? Concerning the drive letters, I am not even sure that they are compatible with the spec, because drive letters amount to a multi-root hierarchy (there is nothing above, say, "c:"), and I have the impression that this violates the basic assumptions of the spec. HOWEVER ...
I feel that I shall need to read the spec from start to end very carefully in order to say anything with assurance, due to the subtlety of the subject matter. Now I have the problem that until mid February I am under severe time pressure so that I cannot tackle the task. I propose the following: I leave the matter alone until then, after which I shall indeed analyze the spec and report the results to you. (In fact I have long since wished to understand URIs completely, so I commit myself to the task with pleasure.) Ok?
Cheers,Hans-Jürgen
Quoted text · Christian Grün · 1 line
Christian Grün <christian.gruen at gmail.com> schrieb am 9:10 Samstag, 24.Januar 2015:
Hans-Jürgen,
Thanks for the report; I can confirm that the trailing slash is missing in the result. I noticed it's quite a hassle to implement all the XQuery URI resolutions in Java, because Java's default classes do not comply 100% with RFC 3986.
I have added a new GitHub issue [1].
As you seem to have spent some time with the spec, can you possibly tell me how the following URIs should correctly be resolved? I tried some XQuery implementations, they all gave me different results...
declare base-uri "../../../../../../../../../../../..";
static-base-uri()
declare base-uri "C:/";
static-base-uri()
declare base-uri "C:/..";
static-base-uri()Thanks in advance,
Christian
[1] https://github.com/BaseXdb/basex/issues/1062
Quoted text · Hans-Juergen Rennau · 56 lines
On Fri, Jan 23, 2015 at 11:09 PM, Hans-Juergen Rennau <hrennau at yahoo.de> wrote: > Dear BaseX team, > > I think there is a bug in the determination of the static base URI in the > special case that a base URI declaration contains a relative URI equal to or > starting with "..". > > Consider this declaration: > declare base-uri ".."; > > The effect should be that relative URIs are resolved against the PARENT > directory of the directory containing the query. > > If the query is located at, say, file:///a/b/c/query.xq, I would expect the > static base-uri to be /a/b/, so that a URI like "abc.xml" would be resolved > to file:///a/b/abc.xml. > > However, the static base URI as determined by BaseX in this case misses the > trailing /, it is: file:///a/b > The effect is that a URI like "abc.xml" would be resolved to > file:///a/abc.xml > In other words: URIs are resolved against the "GRAND-PARENT" directory of > the query. > > Final remark: the effect of resolving URIs against the parent directory of > the query is achieved by the surprising base URI declaration: > > declare base-uri "."; > > which is not what I would expect. > > Conclusion: the way to achieve a resolving of relative URIs against the > parent directory of the query should be achieved by the base URI declaration > ".." - and no other value. > > Kind regards, > Hans-Juergen > > Full example: > Query ( file file:///projects/infospace/pcol/test.xq); > > declare base-uri ".."; > declare variable $uri external; > > string-join(( > 'query-file: file:///projects/infospace/pcol/test.xq', > concat('static-base-uri: ', static-base-uri()), > concat('resolve-uri("try.xml")=', resolve-uri("try.xml")) > ), '
') > > Output: > query-file: file:///projects/infospace/pcol/test.xq > static-base-uri: file:///C:/projects/infospace > resolve-uri("try.xml")=file:/C:/projects/try.xml > >
CG
Christian Grün27 Jan 2015 08:38 #
Hi Hans-Jürgen,
Thanks for your reply. And don't worry, I didn't expect you to give answers on all those corner cases. I remember we have an open issue related to URI parsing [1]. If we decide to implement our own URI parser, things may be solved by itself.
Christian
[1] https://github.com/BaseXdb/basex/issues/928
Quoted text · Hans-Juergen Rennau · 126 lines
On Mon, Jan 26, 2015 at 10:35 PM, Hans-Juergen Rennau <hrennau at yahoo.de> wrote: > Christian, > > unfortunately I cannot give the answers to your questions. My attempts to > find answers in the spec rather quickly failed. Concerning the first case, > the many ".."s, supposedly more of them than the base URI has path steps, my > feeling is that there is no sensible alternative to resolving the URI to > "file:///" (or "file:/" or "file://", I wonder...) - what else could > possibly be the intention? Concerning the drive letters, I am not even sure > that they are compatible with the spec, because drive letters amount to a > multi-root hierarchy (there is nothing above, say, "c:"), and I have the > impression that this violates the basic assumptions of the spec. HOWEVER ... > > I feel that I shall need to read the spec from start to end very carefully > in order to say anything with assurance, due to the subtlety of the subject > matter. Now I have the problem that until mid February I am under severe > time pressure so that I cannot tackle the task. I propose the following: I > leave the matter alone until then, after which I shall indeed analyze the > spec and report the results to you. (In fact I have long since wished to > understand URIs completely, so I commit myself to the task with pleasure.) > Ok? > > Cheers, > Hans-Jürgen > > > > > Christian Grün <christian.gruen at gmail.com> schrieb am 9:10 Samstag, > 24.Januar 2015: > > > Hans-Jürgen, > > Thanks for the report; I can confirm that the trailing slash is > missing in the result. I noticed it's quite a hassle to implement all > the XQuery URI resolutions in Java, because Java's default classes do > not comply 100% with RFC 3986. > > I have added a new GitHub issue [1]. > > As you seem to have spent some time with the spec, can you possibly > tell me how the following URIs should correctly be resolved? I tried > some XQuery implementations, they all gave me different results... > > declare base-uri "../../../../../../../../../../../.."; > static-base-uri() > > declare base-uri "C:/"; > static-base-uri() > > declare base-uri "C:/.."; > static-base-uri() > > Thanks in advance, > Christian > > [1] https://github.com/BaseXdb/basex/issues/1062 > > > > > On Fri, Jan 23, 2015 at 11:09 PM, Hans-Juergen Rennau <hrennau at yahoo.de> > wrote: >> Dear BaseX team, >> >> I think there is a bug in the determination of the static base URI in the >> special case that a base URI declaration contains a relative URI equal to >> or >> starting with "..". >> >> Consider this declaration: >> declare base-uri ".."; >> >> The effect should be that relative URIs are resolved against the PARENT >> directory of the directory containing the query. >> >> If the query is located at, say, file:///a/b/c/query.xq, I would expect >> the >> static base-uri to be /a/b/, so that a URI like "abc.xml" would be >> resolved >> to file:///a/b/abc.xml. >> >> However, the static base URI as determined by BaseX in this case misses >> the >> trailing /, it is: file:///a/b >> The effect is that a URI like "abc.xml" would be resolved to >> file:///a/abc.xml >> In other words: URIs are resolved against the "GRAND-PARENT" directory of >> the query. >> >> Final remark: the effect of resolving URIs against the parent directory of >> the query is achieved by the surprising base URI declaration: >> >> declare base-uri "."; >> >> which is not what I would expect. >> >> Conclusion: the way to achieve a resolving of relative URIs against the >> parent directory of the query should be achieved by the base URI >> declaration >> ".." - and no other value. >> >> Kind regards, >> Hans-Juergen >> >> Full example: >> Query ( file file:///projects/infospace/pcol/test.xq); >> >> declare base-uri ".."; >> declare variable $uri external; >> >> string-join(( >> 'query-file: file:///projects/infospace/pcol/test.xq', >> concat('static-base-uri: ', static-base-uri()), >> concat('resolve-uri("try.xml")=', resolve-uri("try.xml")) >> ), '
') >> >> Output: >> query-file: file:///projects/infospace/pcol/test.xq >> static-base-uri: file:///C:/projects/infospace >> resolve-uri("try.xml")=file:/C:/projects/try.xml >> >> > >
CG
Hello Hans-Jürgen,
It has been a while, but the erroneous behavior of the base-uri declaration should now be history (if it doesn't sound too pathetic). A new snapshot will be available later today..
Regarding the declaration of invalid paths (e.g. with multiple parent references), my impression so far is that every XQuery implementation does something different, and I am not sure if/where it is
well-defined in the specs. For now, I'll simply assume that those cases are (as Michael Kay likes to put it) pathological, and I have closed the corresponding issue in our bug tracker [1].
Christian
[1] https://github.com/BaseXdb/basex/issues/1062
Quoted text · Christian Grün · 88 lines
On Sat, Jan 24, 2015 at 9:02 AM, Christian Grün <christian.gruen at gmail.com> wrote: > Hans-Jürgen, > > Thanks for the report; I can confirm that the trailing slash is > missing in the result. I noticed it's quite a hassle to implement all > the XQuery URI resolutions in Java, because Java's default classes do > not comply 100% with RFC 3986. > > I have added a new GitHub issue [1]. > > As you seem to have spent some time with the spec, can you possibly > tell me how the following URIs should correctly be resolved? I tried > some XQuery implementations, they all gave me different results... > > declare base-uri "../../../../../../../../../../../.."; > static-base-uri() > > declare base-uri "C:/"; > static-base-uri() > > declare base-uri "C:/.."; > static-base-uri() > > Thanks in advance, > Christian > > [1] https://github.com/BaseXdb/basex/issues/1062 > > > > > On Fri, Jan 23, 2015 at 11:09 PM, Hans-Juergen Rennau <hrennau at yahoo.de> wrote: >> Dear BaseX team, >> >> I think there is a bug in the determination of the static base URI in the >> special case that a base URI declaration contains a relative URI equal to or >> starting with "..". >> >> Consider this declaration: >> declare base-uri ".."; >> >> The effect should be that relative URIs are resolved against the PARENT >> directory of the directory containing the query. >> >> If the query is located at, say, file:///a/b/c/query.xq, I would expect the >> static base-uri to be /a/b/, so that a URI like "abc.xml" would be resolved >> to file:///a/b/abc.xml. >> >> However, the static base URI as determined by BaseX in this case misses the >> trailing /, it is: file:///a/b >> The effect is that a URI like "abc.xml" would be resolved to >> file:///a/abc.xml >> In other words: URIs are resolved against the "GRAND-PARENT" directory of >> the query. >> >> Final remark: the effect of resolving URIs against the parent directory of >> the query is achieved by the surprising base URI declaration: >> >> declare base-uri "."; >> >> which is not what I would expect. >> >> Conclusion: the way to achieve a resolving of relative URIs against the >> parent directory of the query should be achieved by the base URI declaration >> ".." - and no other value. >> >> Kind regards, >> Hans-Juergen >> >> Full example: >> Query ( file file:///projects/infospace/pcol/test.xq); >> >> declare base-uri ".."; >> declare variable $uri external; >> >> string-join(( >> 'query-file: file:///projects/infospace/pcol/test.xq', >> concat('static-base-uri: ', static-base-uri()), >> concat('resolve-uri("try.xml")=', resolve-uri("try.xml")) >> ), '
') >> >> Output: >> query-file: file:///projects/infospace/pcol/test.xq >> static-base-uri: file:///C:/projects/infospace >> resolve-uri("try.xml")=file:/C:/projects/try.xml >> >>
Written for BaseX 7.9, 8.1. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery