Skip to content

Commit

Permalink
811 redirection error if the url contains parameters (#812)
Browse files Browse the repository at this point in the history
* remove add_filter, to make the filter useful

* fix redirect with params

* fix tests

---------

Co-authored-by: Anja Möller <22166320+andernath@users.noreply.github.com>
  • Loading branch information
ingoKrOffice and andernath authored Jun 27, 2024
1 parent ae56458 commit 898af59
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
4 changes: 0 additions & 4 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,6 @@ function customFieldCallback( $pDI, $format, $limitEllipsis, $meta_key ) {
}
});

add_filter('oo_is_detailpage_redirection', function($value) {
return $value;
});

$pEstateRedirection = apply_filters('oo_is_detailpage_redirection', true);

add_action('parse_request', function(WP $pWP) use ($pDI, $pEstateRedirection) {
Expand Down
8 changes: 2 additions & 6 deletions plugin/Controller/EstateDetailUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,9 @@ public function getUrlWithEstateTitle(int $estateId, string $title = null, strin
$urlLsSwitcher = $urlElements['scheme'] . '://' . $urlElements['host'] . $newPath . '/' . $urlTemp;

if (!empty($getParameters)) {
if ($pEstateRedirection) {
$urlLsSwitcher .= '';
} elseif(!$tickerUrlHasTitleFlag) {
$urlLsSwitcher .= '?' . http_build_query($getParameters);
}
$urlLsSwitcher = add_query_arg($getParameters,$urlLsSwitcher);
}

return $urlLsSwitcher;
}
}
}
2 changes: 1 addition & 1 deletion plugin/Utility/Redirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,6 @@ public function getUri()
public function getCurrentLink(): string
{
global $wp;
return home_url(add_query_arg($_GET, trailingslashit($wp->request)));
return home_url(add_query_arg($_GET, $wp->request));
}
}
18 changes: 9 additions & 9 deletions tests/TestClassEstateDetailUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function testGetUrlWithFilterTrueAndEnableOptionShowTitleWithParameter()
$title = 'test-title';
$pInstance = $this->_pContainer->get(EstateDetailUrl::class);
$url = 'https://www.onoffice.de/detail/123?lang=en';
$expectedUrl = 'https://www.onoffice.de/detail/123-test-title';
$expectedUrl = 'https://www.onoffice.de/detail/123-test-title?lang=en';
$this->assertEquals($expectedUrl, $pInstance->getUrlWithEstateTitle($estateId, $title, $url, false, $pEstateRedirection));
}

Expand All @@ -169,7 +169,7 @@ public function testGetUrlWithFilterTrueAndDisableOptionShowTitleWithParameter()
$title = 'test-title';
$pInstance = $this->_pContainer->get(EstateDetailUrl::class);
$url = 'https://www.onoffice.de/detail/123?lang=en';
$expectedUrl = 'https://www.onoffice.de/detail/123';
$expectedUrl = 'https://www.onoffice.de/detail/123?lang=en';
$this->assertEquals($expectedUrl, $pInstance->getUrlWithEstateTitle($estateId, $title, $url, false, $pEstateRedirection));
}

Expand Down Expand Up @@ -210,16 +210,16 @@ public function testGetUrlWithFilterFalseAndEnableOptionShowTitleWithParameter()
$expectedUrlHasTitleWithoutParamster = 'https://www.onoffice.de/detail/123-test-title';
$this->assertEquals($expectedUrlHasTitleWithoutParamster, $pInstance->getUrlWithEstateTitle($estateId, $title, $urlHasTitleWithoutParamster, false, $pEstateRedirection));

$urlWithoutTitle = 'https://www.onoffice.de/detail/123/?lang=en';
$urlWithoutTitle = 'https://www.onoffice.de/detail/123?lang=en';
$expectedUrlWithoutTitle = 'https://www.onoffice.de/detail/123?lang=en';
$this->assertEquals($expectedUrlWithoutTitle, $pInstance->getUrlWithEstateTitle($estateId, $title, $urlWithoutTitle, false, $pEstateRedirection));

$urlHasTitleHasParamster = 'https://www.onoffice.de/detail/123-test-title';
$expectedUrlHasTitleHasParamster = 'https://www.onoffice.de/detail/123-test-title';
$this->assertEquals($expectedUrlHasTitleHasParamster, $pInstance->getUrlWithEstateTitle($estateId, $title, $urlHasTitleHasParamster, true, $pEstateRedirection));
$urlHasTitleHasParameter = 'https://www.onoffice.de/detail/123-test-title?lang=en';
$expectedUrlHasTitleHasParameter = 'https://www.onoffice.de/detail/123-test-title?lang=en';
$this->assertEquals($expectedUrlHasTitleHasParameter, $pInstance->getUrlWithEstateTitle($estateId, $title, $urlHasTitleHasParameter, true, $pEstateRedirection));

$urlHasTitle = 'https://www.onoffice.de/detail/123-test-title/?lang=en';
$expectedUrlHasTitle = 'https://www.onoffice.de/detail/123-test-title';
$urlHasTitle = 'https://www.onoffice.de/detail/123-test-title?lang=en';
$expectedUrlHasTitle = 'https://www.onoffice.de/detail/123-test-title?lang=en';
$this->assertEquals($expectedUrlHasTitle, $pInstance->getUrlWithEstateTitle($estateId, $title, $urlHasTitle, true, $pEstateRedirection));
}
}
}
2 changes: 1 addition & 1 deletion tests/TestClassRedirectIfOldUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function stestInstance()
*/
public function testGetCurrentLink()
{
$this->assertEquals( 'http://example.org/detail-view/123/', $this->_pRedirectIfOldUrl->getCurrentLink() );
$this->assertEquals( 'http://example.org/detail-view/123', $this->_pRedirectIfOldUrl->getCurrentLink() );
}

/**
Expand Down

0 comments on commit 898af59

Please sign in to comment.