Skip to content

Commit

Permalink
add anchor check (#2070)
Browse files Browse the repository at this point in the history
* add anchor check

* remove unused class

* changelog
  • Loading branch information
nadar committed Nov 24, 2020
1 parent 764500a commit 2ddfac9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
In order to read more about upgrading and BC breaks have a look at the [UPGRADE Document](UPGRADE.md).

## 1.8.0 (10. Novemeber 2020)
## 1.8.0 (24. Novemeber 2020)

+ [#2069](https://github.com/luyadev/luya/issues/2069) `WebsiteLink` does not prepend the URL protocol when an acnhor link `#foo-bar` is provided.
+ [#2067](https://github.com/luyadev/luya/pull/2067) Added new `['sort' => false]` option to ExportHelper::csv() and ExportHelper::xls().

## 1.7.1 (23. September 2020)
Expand Down
3 changes: 3 additions & 0 deletions core/web/WebsiteLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public function setHref($href)
{
if (StringHelper::startsWith($href, '//')) {
$this->_href = Url::base(true) . str_replace('//', '/', $href);
} elseif (StringHelper::startsWith($href, '#')) {
// When an anchor link is given, do not modify the link. This can be usefull for one pagers
$this->_href = $href;
} else {
$this->_href = Url::ensureHttp($href);
}
Expand Down
18 changes: 18 additions & 0 deletions tests/core/web/ExternalLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,22 @@ public function testSchemaHttpMissing()

$this->assertContains('public_html/go/there?p=1', $link->href);
}

public function testTarget()
{
$link = new WebsiteLink(['href' => 'https://luya.io', 'target' => '_blank']);

$this->assertSame('_blank', $link->getTarget());
}

public function testAnchorLink()
{
$link = new WebsiteLink(['href' => '#my-super-anchor']);

$this->assertSame('#my-super-anchor', $link->getHref());

$link = new WebsiteLink(['href' => '//page-link#my-super-anchor']);

$this->assertContains('/page-link#my-super-anchor', $link->getHref());
}
}

0 comments on commit 2ddfac9

Please sign in to comment.