I have unexpected resultes while generating absolute path from relative
php version 5.5.9

$base_url = 'http://www.example.com/img';
$url = 'large/myimage.png';

$result_url = http_request_create_absolute_url($url, $base_url);
print $result_url; // http://www.example.com/large/myimage.png
// expect http://www.example.com/large/myimage.png
$base_url = 'http://www.example.com/files/img/';
$url = 'myimage.png';

$result_url = http_request_create_absolute_url($url, $base_url);
print $result_url; // http://www.example.com/files/myimage.png
// expect http://www.example.com/files/img/myimage.png

Comments

zniki.ru created an issue. See original summary.

nikolay shapovalov’s picture

Issue summary: View changes
nikolay shapovalov’s picture

StatusFileSize
new451 bytes
nikolay shapovalov’s picture

Status: Active » Needs review
nikolay shapovalov’s picture

Title: http_request_create_absolute_url() ignore path in $base_url » http_request_create_absolute_url() ignore last path in $base_url
nikolay shapovalov’s picture

Issue summary: View changes
nikolay shapovalov’s picture

Issue summary: View changes
nikolay shapovalov’s picture

Status: Needs review » Needs work
nikolay shapovalov’s picture

Issue tags: -Needs tests
StatusFileSize
new10.13 KB

Add tests.
Make functions results more expected.

If you still have questions, just look '/tests/http_request.test', after patch apply.
If somebody can add more test-cases, it would be great.

nikolay shapovalov’s picture

Status: Needs work » Needs review
nikolay shapovalov’s picture

megachriz’s picture

Are you using this function directly? I haven't examined the changes deeply yet, but I wonder if it could break any existing workflows. Well, I should find time to take a closer look at it.

nikolay shapovalov’s picture

Yes I am, and also some contrib modules use this function: Feeds Crawler.

I wonder if it could break any existing workflows

I hope not, all test are passed.

// Now it can be several '..' in url.
http_request_create_absolute_url('../../d', 'http://www.example.com/a/b/c/');
// before http://www.example.com/a/b/d
// now    http://www.example.com/a/d

// Also it depends if base url have trailing slash or not.
http_request_create_absolute_url('d', 'http://www.example.com/a/');
// before http://www.example.com/d
// now    http://www.example.com/a/d

http_request_create_absolute_url('d', 'http://www.example.com/a');
// before http://www.example.com/d
// now    http://www.example.com/d

// And now it process $url even if it starts with /.
http_request_create_absolute_url('/d/./j/k/../l/', 'http://www.example.com/a');
// before http://www.example.com/d/./j/k/../l
// now    http://www.example.com/d/j/l
Well, I should find time to take a closer look at it.

I think most easy way to see difference, run tests from the patch for curent version in 7.x-2.x and this patched version.

But there are some more bugs/features. I not sure about them. But I think if we wouldn't fix them, it's better to update comment for this function.

// mailto: skype: magnet: in $url and 
http_request_create_absolute_url('mailto:bob@example.com', 'http://example.com/');
// now http://example.com/mailto:bob@example.com
// should be false or use rawurlencode http://example.com/mailto%3Abob%40example.com

// Non ascii chars
http_request_create_absolute_url('Яд', 'https://ru.wikipedia.org/wiki/');
// now false
// should be https://ru.wikipedia.org/wiki/%D0%AF%D0%B4

  • MegaChriz committed 72e0e00 on 7.x-2.x authored by zniki.ru
    Issue #2584443 by zniki.ru: http_request_create_absolute_url() ignore...
megachriz’s picture

Status: Needs review » Fixed

I've taken a closer look, especially at the tests. The expected output of each assertion made sense to me, so I went ahead and committed your changes! I did make a few changes to your patch, namely some spelling in the code comments and in the test I changed the key for each expected result from "result" to "expected". Lastly, I changed the t() call in the test to a format_string() call. Assert messages in tests don't have to be translated.

Thanks for your contribution!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.