Browse Source

Normalize URLs before establishing feed uniqueness

microsub
J. King 5 years ago
parent
commit
3439895779
  1. 3
      lib/Database.php
  2. 11
      tests/cases/Database/SeriesSubscription.php
  3. 2
      tests/cases/Misc/TestURL.php

3
lib/Database.php

@ -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();

11
tests/cases/Database/SeriesSubscription.php

@ -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);

2
tests/cases/Misc/TestURL.php

@ -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…
Cancel
Save