Skip to content

Commit 4db2833

Browse files
author
Skrol29
committed
TBS 3.12.2
1 parent 5ce71ce commit 4db2833

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66

7+
## [3.12.2] - 2020-11-03
8+
9+
### Fixed
10+
11+
- Parameter 'magnet=#' used with MergeBlock() makes erroneous merging when magnet is activated, except for the first occurence.
12+
713
## [3.12.1] - 2020-10-24
814

915
### Fixed

tbs_class.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*
44
* TinyButStrong - Template Engine for Pro and Beginners
55
*
6-
* @version 3.12.1 for PHP 5, 7, 8
7-
* @date 2020-10-21
6+
* @version 3.12.2 for PHP 5, 7, 8
7+
* @date 2020-11-03
88
* @link http://www.tinybutstrong.com Web site
99
* @author http://www.tinybutstrong.com/onlyyou.html
1010
* @license http://opensource.org/licenses/LGPL-3.0 LGPL-3.0
@@ -655,7 +655,7 @@ class clsTinyButStrong {
655655
public $ExtendedMethods = array();
656656
public $ErrCount = 0;
657657
// Undocumented (can change at any version)
658-
public $Version = '3.12.1';
658+
public $Version = '3.12.2';
659659
public $Charset = '';
660660
public $TurboBlock = true;
661661
public $VarPrefix = '';
@@ -1761,7 +1761,8 @@ function meth_Locator_Replace(&$Txt,&$Loc,&$Value,$SubStart) {
17611761
if ($Loc->PrmLst['magnet']==='#') {
17621762
if (!isset($Loc->AttBeg)) {
17631763
$Loc->PrmLst['att'] = '.';
1764-
$this->f_Xml_AttFind($Txt,$Loc,true,$this->AttDelim);
1764+
// no moving because att info would be modified and thus become wrong regarding to the eventually cached source
1765+
$this->f_Xml_AttFind($Txt,$Loc,false,$this->AttDelim);
17651766
}
17661767
if (isset($Loc->AttBeg)) {
17671768
$Loc->MagnetId = -3;
@@ -1789,7 +1790,12 @@ function meth_Locator_Replace(&$Txt,&$Loc,&$Value,$SubStart) {
17891790
case 0: break;
17901791
case -1: $CurrVal = ' '; break; // Enables to avoid null cells in HTML tables
17911792
case -2: $CurrVal = $Loc->PrmLst['ifempty']; break;
1792-
case -3: $Loc->Enlarged = true; $Loc->PosBeg = $Loc->AttBegM; $Loc->PosEnd = $Loc->AttEnd; break;
1793+
case -3:
1794+
// magnet=#
1795+
$Loc->Enlarged = true;
1796+
$Loc->PosBeg = ($Txt[$Loc->AttBeg-1]===' ') ? $Loc->AttBeg-1 : $Loc->AttBeg;
1797+
$Loc->PosEnd = $Loc->AttEnd;
1798+
break;
17931799
case 1:
17941800
$Loc->Enlarged = true;
17951801
$this->f_Loc_EnlargeToTag($Txt,$Loc,$Loc->PrmLst['magnet'],false);
@@ -4845,8 +4851,9 @@ static function f_Loc_Sort(&$LocLst, $DelEmbd, $iFirst = 0) {
48454851

48464852
/**
48474853
* Prepare all informations to move a locator according to parameter "att".
4848-
* @param mixed $MoveLocLst true to simple move the loc, or an array of loc to rearrange the list after the move.
4849-
* Note: rearrange doest not work with PHP4.
4854+
*
4855+
* @param false|true|array $MoveLocLst true to simple move the loc, or an array of loc to rearrange the list after the move.
4856+
* Note: rearrange doest not work with PHP4.
48504857
*/
48514858
static function f_Xml_AttFind(&$Txt,&$Loc,$MoveLocLst=false,$AttDelim=false,$LocLst=false) {
48524859
// att=div#class ; att=((div))#class ; att=+((div))#class
@@ -4933,6 +4940,12 @@ static function f_Xml_AttFind(&$Txt,&$Loc,$MoveLocLst=false,$AttDelim=false,$Loc
49334940

49344941
}
49354942

4943+
/**
4944+
* Move a locator in the source from its original location to the attribute location.
4945+
* The new locator string is only '[]', no need to copy the full source since all parameters are saved in $Loc.*
4946+
*
4947+
* @param false|true|array $MoveLocLst If the function is called from the caching process, then this value is an array.
4948+
*/
49364949
static function f_Xml_AttMove(&$Txt, &$Loc, $AttDelim, &$MoveLocLst) {
49374950

49384951
if ($AttDelim===false) $AttDelim = $Loc->AttDelimChr;
@@ -4990,11 +5003,8 @@ static function f_Xml_AttMove(&$Txt, &$Loc, $AttDelim, &$MoveLocLst) {
49905003
$Loc->AttTagEnd += $InsLen;
49915004
}
49925005

4993-
$Loc->PrevPosBeg = $Loc->PosBeg;
4994-
$Loc->PrevPosEnd = $Loc->PosEnd;
49955006
$Loc->PosBeg = $PosBeg;
49965007
$Loc->PosEnd = $PosEnd;
4997-
$Loc->AttBegM = ($Txt[$Loc->AttBeg-1]===' ') ? $Loc->AttBeg-1 : $Loc->AttBeg; // for magnet=#
49985008

49995009
// for CacheField
50005010
if (is_array($MoveLocLst)) {

testunit/include/TBSUnitTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function getTemplateDir() {
104104
* @return boolean True on pass
105105
*/
106106
function assertEqualMergeString($expected, $message='%s') {
107-
$result = $this->getTBSRender();
107+
$result = $this->getTBSRender();
108108
return $this->assertEqual($result, $expected, $message);
109109
}
110110

testunit/testcase/AttTestCase.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ function testFields() {
7979
}
8080

8181
function testMergeBlocks() {
82+
8283
$blk = array();
8384
$blk[] = array('id'=>'AttCache x12', 'val'=>'effect1');
8485
$blk[] = array('id'=>'AttCache x13', 'val'=>'effect2');
@@ -93,6 +94,7 @@ function testMergeBlocks() {
9394

9495
// test normal with parent tag specification
9596
$this->assertEqualMergeBlockFiles('att_test3.html', array('blk'=>$blk), 'att_test3_result.html', "test blocks #3");
97+
9698
}
9799

98100
function testMergeBlocksWithCachedFields() {
@@ -150,6 +152,21 @@ function testMergeBlocksWithCachedFields() {
150152
$this->assertErrorMergeBlockString('<div>[b.val;att=+span#width][b.id;block=div]/[b.id]/[b.id]<span></span></div>', array('b'=>$data), "test blocks CacheField - forward + attribute not yet exists + jump 3 fields");
151153
$this->assertErrorMergeBlockString('<div>[b.val;att=+span#width][b.id;block=div]/[b.id]/[b.id]<span width="0"></span></div>', array('b'=>$data), "test blocks CacheField - forward + attribute already exists + jump 3 fields");
152154
}
155+
156+
// magnet = #
157+
158+
$data = array();
159+
$data[] = array('ref' => 'r1');
160+
$data[] = array('ref' => '');
161+
$data[] = array('ref' => '');
162+
$data[] = array('ref' => '');
163+
$data[] = array('ref' => 'r5');
164+
165+
// A fixed bug since 3.12.2
166+
if ( $this->atLeastTBSVersion('3.12.2') ) {
167+
$this->assertEqualMergeBlockString('<a href="[b.ref;block=a;magnet=#]"></a>', array('b'=>$data), '<a href="r1"></a><a></a><a></a><a></a><a href="r5"></a>', "test blocks CacheField + magnet = #");
168+
}
169+
153170

154171
}
155172

0 commit comments

Comments
 (0)