Skip to content

Commit

Permalink
Ignore expanding short links with trailing path
Browse files Browse the repository at this point in the history
  • Loading branch information
danon committed Jan 30, 2024
1 parent 73cc5e2 commit bc87ea2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/Services/Parser/Parsers/SetCanonicalHref.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private function canonicalHref(string $href): string

private function shortLinkPostId(string $href): ?int
{
if (\preg_match('#Forum/(\d+)#', $href, $match)) {
if (\preg_match('#Forum/(\d+)$#', $href, $match)) {
return $match[1];
}
return null;
Expand Down
20 changes: 16 additions & 4 deletions tests/Unit/Post/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,27 @@ class Test extends TestCase
use Post\Fixture\Assertion;
use Post\Fixture\Models;

public function test()
/**
* @test
*/
public function shortLink()
{
// given
[$topicId, $postId] = $this->newPostInCategoryTopic('origin-category', 'Origin topic');
// when
$post = $this->newPost("[title](/Forum/$postId)");
// then
$this->assertThat(
$this->linkInContent($post->topic),
$this->identicalTo("/Forum/origin-category/{$topicId}-origin_topic?p=$postId#id$postId"));
$this->assertSame(
"/Forum/origin-category/{$topicId}-origin_topic?p=$postId#id$postId",
$this->linkInContent($post->topic));
}

/**
* @test
*/
public function brokenLink()
{
$post = $this->newPost("[title](/Forum/123/link)");
$this->assertSame('/Forum/123/link', $this->linkInContent($post->topic));
}
}

0 comments on commit bc87ea2

Please sign in to comment.