[haiku-development] Re: Confusion with BUrl class

  • From: "Mark Hellegers" <mark@xxxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Mon, 17 Apr 2017 20:50:15 +0200 CEST

Hello all,

I am trying to track down a problem with (my use of) BUrl objects and 

am getting a bit stuck in the BUrl source code.
I have the following small test case:

// Standard C headers
#include <stdio.h>

// Haiku headers
#include <support/Url.h>

int main(int argc, char **argv) {

      BUrl base("http://www.example.com/test/example.html";);
      BUrl test1(base, "../index.html");
      BString urlString = test1.UrlString();
      printf("Test 1 url:%s\n", urlString.String());

      BUrl test2(base, "index.html");
      urlString = test2.UrlString();
      printf("Test 2 url:%s\n", urlString.String());
      
      return 0;

}

I am expecting the "Test 1 url" to print "http://www.example.com/index.html" ;
and the "Test 2 url" to print "http://www.example.com/test/index.html", ;
but they both print "http://www.example.com/test/index.html" ;
(expected 
output of "Test 2 url"). Is this expectation wrong?
I looked at the source code of BUrl to see where this is going wrong 
and it seems that at the point where a BUrl is constructed, the ".." 
part is lost. This seems to happen in _ExplodeUrlString. It tries to 
determine if it starts with a protocol and I cannot follow the logic 
of 
that check (function explode_is_protocol_char). The _ExplodeUrlString 
mentions that it is an implementation of a regular expression, but I 
am 
not very good at regular expressions. I thought that the protocol 
part 
is everything in front of "://", but perhaps that is a bit 
simplistic.


I dug a bit deeper in the code and I think the protocol check is not 
the problem as it sees in the next step that there is no ":" character 
and a bit later it checks if it is a path. If it is, it calls SetPath 
which immediately starts parsing it as if it is a complete url instead 
of only a relative url. This seems to remove the ".." part.
I wanted the check the documentation of the BUrl class to see what we 
are supposed to store in a BUrl, but there does not appear to be any 
documentation in that respect.
I think I can fix my particular problem by changing the code in the 
BUrl constructor I am using not to create a BUrl of the location 
parameter, but I have no idea what the effect of this in general will 
be.

Kind regards,

Mark Hellegers


--
Spangalese for beginners

`Lidbush don uenen deksez.'
`The Library is full of tar.'



Other related posts: