mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
Normalize URLs before establishing feed uniqueness
This commit is contained in:
parent
a175561574
commit
3439895779
3 changed files with 13 additions and 3 deletions
|
@ -12,6 +12,7 @@ use JKingWeb\Arsse\Misc\Query;
|
|||
use JKingWeb\Arsse\Context\Context;
|
||||
use JKingWeb\Arsse\Misc\Date;
|
||||
use JKingWeb\Arsse\Misc\ValueInfo;
|
||||
use JKingWeb\Arsse\Misc\URL;
|
||||
|
||||
/** The high-level interface with the database
|
||||
*
|
||||
|
@ -992,6 +993,8 @@ class Database {
|
|||
* @param boolean $discover Whether to perform newsfeed discovery if $url points to an HTML document
|
||||
*/
|
||||
public function feedAdd(string $url, string $fetchUser = "", string $fetchPassword = "", bool $discover = true): int {
|
||||
// normalize the input URL
|
||||
$url = URL::normalize($url);
|
||||
// check to see if the feed already exists
|
||||
$check = $this->db->prepare("SELECT id from arsse_feeds where url = ? and username = ? and password = ?", "str", "str", "str");
|
||||
$feedID = $check->run($url, $fetchUser, $fetchPassword)->getValue();
|
||||
|
|
|
@ -202,9 +202,10 @@ trait SeriesSubscription {
|
|||
$url = "http://example.org/feed1";
|
||||
$feedID = $this->nextID("arsse_feeds");
|
||||
Phake::when(Arsse::$db)->feedUpdate->thenThrow(new FeedException($url, new \PicoFeed\Client\InvalidUrlException()));
|
||||
$this->assertException("invalidUrl", "Feed");
|
||||
try {
|
||||
Arsse::$db->subscriptionAdd($this->user, $url, "", "", false);
|
||||
} catch (FeedException $e) {
|
||||
} finally {
|
||||
Phake::verify(Arsse::$user)->authorize($this->user, "subscriptionAdd");
|
||||
Phake::verify(Arsse::$db)->feedUpdate($feedID, true);
|
||||
$state = $this->primeExpectations($this->data, [
|
||||
|
@ -212,8 +213,6 @@ trait SeriesSubscription {
|
|||
'arsse_subscriptions' => ['id','owner','feed'],
|
||||
]);
|
||||
$this->compareExpectations(static::$drv, $state);
|
||||
$this->assertException("invalidUrl", "Feed");
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,6 +222,12 @@ trait SeriesSubscription {
|
|||
Arsse::$db->subscriptionAdd($this->user, $url);
|
||||
}
|
||||
|
||||
public function testAddADuplicateSubscriptionWithEquivalentUrl() {
|
||||
$url = "http://EXAMPLE.COM/feed2";
|
||||
$this->assertException("constraintViolation", "Db", "ExceptionInput");
|
||||
Arsse::$db->subscriptionAdd($this->user, $url);
|
||||
}
|
||||
|
||||
public function testAddADuplicateSubscriptionViaRedirection() {
|
||||
$url = "http://localhost:8000/Feed/Parsing/Valid";
|
||||
Arsse::$db->subscriptionAdd($this->user, $url);
|
||||
|
|
|
@ -23,6 +23,8 @@ class TestURL extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
return [
|
||||
["/", "/"],
|
||||
["//example.com/", "//example.com/"],
|
||||
["/ ", "/ "],
|
||||
["//EXAMPLE.COM/", "//EXAMPLE.COM/"],
|
||||
["http://example.com/", "http://example.com/"],
|
||||
["HTTP://example.com/", "http://example.com/"],
|
||||
["http://example.com", "http://example.com/"],
|
||||
|
|
Loading…
Reference in a new issue