Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Backend/design/html/header_notice_bar_banner.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</div>
</div>
{if $smarty.get.return}
<a class="alert__button" href="{$smarty.get.return|escape:'url'}">
<a class="alert__button" href="{$smarty.get.return|escape}">
{include file='svg_icon.tpl' svgId='return'}
<span>{$btr->general_back|escape}</span>
</a>
Expand Down
2 changes: 1 addition & 1 deletion Init/module.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Okay": "4.5.3",
"version": "1.0.7",
"version": "1.0.8",
"moduleName": "Header Notice Bar",
"vendor": {
"email": "devsviat@proton.me",
Expand Down
29 changes: 29 additions & 0 deletions tests/BackLinkTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Modules\Sviat\HeaderNoticeBar;

use Okay\Modules\Sviat\HeaderNoticeBar\Backend\Controllers\HeaderNoticeBarBannerAdmin;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

/**
* ?return= — це шлях /backend/index.php?…, а |escape:'url' кодував у ньому кожен «/» і «?»:
* href ставав відносним %2Fbackend%2F…, і «Назад» після збереження банера відкривав не список,
* а головну адмінки. Для атрибута потрібне HTML-екранування, а не кодування частини адреси.
*/
class BackLinkTest extends TestCase
{
public function testReturnLinkKeepsThePath(): void
{
$template = dirname((string) (new ReflectionClass(HeaderNoticeBarBannerAdmin::class))->getFileName(), 2)
. '/design/html/header_notice_bar_banner.tpl';
$source = (string) file_get_contents($template);

preg_match_all('/href="\{\$smarty\.get\.return([^}]*)\}"/', $source, $matches);

self::assertNotSame([], $matches[1], 'кнопки «Назад» з ?return= у шаблоні немає');
foreach ($matches[1] as $modifiers) {
self::assertSame('|escape', $modifiers);
}
}
}