Skip to content

Commit

Permalink
Merge pull request #249 from Kdecherf/fix/absoluteStr
Browse files Browse the repository at this point in the history
Fix and refactor makeAbsoluteStr
  • Loading branch information
j0k3r authored Jan 18, 2021
2 parents 987aa6c + 33e6758 commit 07c7f19
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
15 changes: 7 additions & 8 deletions src/Graby.php
Original file line number Diff line number Diff line change
Expand Up @@ -823,21 +823,20 @@ private function makeAbsoluteStr($base, $url)
return false;
}

if (preg_match('!^https?://!i', $url)) {
// already absolute
return $url;
$url = new Uri($url);

if (Uri::isAbsolute($url)) {
return (string) $url;
}

$base = new Uri($base);
// ensure the base has no path at all (to avoid // between host & path)
$base = str_replace($base->getPath(), '', (string) $base);

// in case the url has no scheme & host
if (0 === \strlen($base)) {
// in case the url has no host
if (0 === \strlen($base->getAuthority())) {
return false;
}

return (string) UriResolver::resolve(new Uri($base), new Uri($url));
return (string) UriResolver::resolve($base, $url);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/GrabyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,12 @@ public function dataForMakeAbsoluteStr(): array
['example.org', '/test', false],
['http://example.org', '/test', 'http://example.org/test'],
['http://example.org', '', false],
['http://example.org//test', 'super', 'http://example.org/super'],
['http://example.org//test', 'super', 'http://example.org//super'],
['http://example.org//test', 'http://sample.com', 'http://sample.com'],
['http://example.org/?d=2021/helloworld', 'img/foobar.jpg', 'http://example.org/img/foobar.jpg'],
['http://example.org/folder/page.html', 'visual.jpg', 'http://example.org/folder/visual.jpg'],
['http://example.org/page', 'visual.jpg', 'http://example.org/visual.jpg'],
['http://example.org/folder/', '../visual.jpg', 'http://example.org/visual.jpg'],
];
}

Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/sites/blogger.test
Original file line number Diff line number Diff line change
Expand Up @@ -3296,12 +3296,12 @@ Most developers interact with databases these days through their preferred frame
<li>Implementing the <a href="http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/" target="_blank">MongoDB wire protocol</a></li>
</ol><br/><h4>Again, What's the Point?</h4>
Well, now we can provide you with a stable driver that really shouldn't change all that much, which means less extension upgrades.
<p>Furthermore, it should be faster. The legacy driver, which dates back five years, had unfortunate design quirks that couldn't be fully resolved without a costly rewrite (e.g. the way MongoGridFS invokes MongoCollection methods internally). Creating a brand new, no-frills<sup><a href="http://bjori.blogspot.fr?_escaped_fragment_=#note-1" id="back-note-1">[1]</a></sup>, and simple to use driver gives us a fresh starting point for the next five years.</p>
<p>Furthermore, it should be faster. The legacy driver, which dates back five years, had unfortunate design quirks that couldn't be fully resolved without a costly rewrite (e.g. the way MongoGridFS invokes MongoCollection methods internally). Creating a brand new, no-frills<sup><a href="http://bjori.blogspot.fr/2015/04/next-gen-mongodb-driver.html?_escaped_fragment_=#note-1" id="back-note-1">[1]</a></sup>, and simple to use driver gives us a fresh starting point for the next five years.</p>
<h4>MongoDB PHP Libraries</h4>
Of course, we aren't planning on leaving our users out to dry. Whether or not your framework of choice offers an amazing MongoDB abstraction layer, we do want to make it easy, simple, and natural for you to develop applications with MongoDB.
<p>To that end, we are writing a <a href="https://github.com/10gen-labs/mongo-php-library-prototype" target="_blank">PHP library</a> on top of this new extension, which will have all of the frills, bells, and whistles you might expect. It implements the "<a href="https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst" target="_blank">Standard MongoDB Driver CRUD API</a>" (among others) and we'll continue roll in new features into this library as needed. And because this library will be implemented in PHP, we expect to iterate on new features much more quickly than we were able to do with the legacy driver.</p>
<p>This won't be the only library we will be writing. There are also plans to develop a library to deal with MongoDB administrative tasks (e.g. creating users, reconfiguring wiredTiger nodes, tailing oplogs) and develop tools to introspect MongoDB clusters.</p>
<h4>What do you think?</h4>
The biggest question at this point is: "what else?" What is missing? What are the other pain points you've experienced as a MongoDB developer, that the driver or a library can help with?<br/>
We would love to <a href="https://jira.mongodb.org/secure/CreateIssue.jspa?pid=12484&amp;issuetype=6">hear your feedback</a>! Check out the projects on GitHub (<a href="https://github.com/10gen-labs/mongo-php-driver-prototype">driver</a>, <a href="https://github.com/10gen-labs/mongo-php-library-prototype">library</a>), and let us know what you think.
<p><a href="http://bjori.blogspot.fr?_escaped_fragment_=#back-note-1" id="note-1"><sup>[1]</sup></a> Well.. Almost. There is one <em>frilled</em> feature I'm excited about -- we'll cover that later.<br/></p>
<p><a href="http://bjori.blogspot.fr/2015/04/next-gen-mongodb-driver.html?_escaped_fragment_=#back-note-1" id="note-1"><sup>[1]</sup></a> Well.. Almost. There is one <em>frilled</em> feature I'm excited about -- we'll cover that later.<br/></p>

0 comments on commit 07c7f19

Please sign in to comment.