Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle edge case: "invalid url in base tag" #179

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/BaseHrefTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public function testBaseHref()

public function testBaseHrefContainRelativePath()
{
$web = new \Spekulatius\PHPScraper\PHPScraper;
spekulatius marked this conversation as resolved.
Show resolved Hide resolved
$web = new \Spekulatius\PHPScraper\PHPScraper(['disable_ssl' => true]);

// Navigate to the test page.
// Contains: <base href="/myglasgow/digitalaccessibility/"> (relative path)
$web->go('https://www.gla.ac.uk/myglasgow/digitalaccessibility/');
// Contains: <base href="/links/invalid-base-href.html"> (relative path)
$web->go('https://test-pages.phpscraper.de/links/invalid-base-href.html');
// Check the baseHref
$this->assertSame(
'/myglasgow/digitalaccessibility/',
'/links/invalid-base-href.html',
$web->baseHref
);
}
Expand Down
12 changes: 6 additions & 6 deletions tests/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ public function testCurrentBaseHostWithBaseIsRelativeUri()
$web = new \Spekulatius\PHPScraper\PHPScraper;

// Navigate to the test page.
// Contains: <base href="/myglasgow/digitalaccessibility/">
$web->go('https://www.gla.ac.uk/myglasgow/digitalaccessibility/');
// Contains: <base href="/links/invalid-base-href.html">
$web->go('https://test-pages.phpscraper.de/links/invalid-base-href.html');

// Check the base href being passed through the current base host.
$this->assertSame(
'https://www.gla.ac.uk',
'https://test-pages.phpscraper.de',
$web->currentBaseHost
);
}
Expand Down Expand Up @@ -200,17 +200,17 @@ public function testMakeUrlAbsoluteConsiderBaseHrefIsRelativeUrl()
* It contains:
*
* ```html
* <base href="/myglasgow/digitalaccessibility/">
* <base href="/links/invalid-base-href.html">
* ```
*
* While it's located on `test-pages.phpscraper.de`.
*
* This page isn't actually used. It's purely to set the context.
*/
$web->go('https://www.gla.ac.uk/myglasgow/digitalaccessibility/');
$web->go('https://test-pages.phpscraper.de/links/invalid-base-href.html');

$this->assertSame(
'https://www.gla.ac.uk/test/index.html',
'https://test-pages.phpscraper.de/test/index.html',
$web->makeUrlAbsolute('test/index.html'),
);
}
Expand Down