Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit b692b6f

Browse files
committed
Update for 3.1.25
1 parent 0aa037d commit b692b6f

File tree

26 files changed

+44
-1500
lines changed

26 files changed

+44
-1500
lines changed

PHPUnit_Smarty.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
7474
'PHPUnit_Smarty' => array('config', 'pdo', 'init'),
7575
);
7676

77+
private $dsMap = array('/' => array(array('\\', '/./'), '/.'),
78+
'\\' => array(array('/', '\\.\\'), '\\.'),
79+
);
80+
7781
/**
7882
* This method is called before the first test of this test class is run.
7983
*
@@ -311,8 +315,7 @@ public function buildSourcePath($tpl, $name = null, $type = null, $dir = null)
311315
case 'file':
312316
case 'filetest':
313317
case 'php':
314-
return $dir . $name;
315-
return $this->normalizePath($dir . $name);
318+
return $this->normalizePath($dir . $name);
316319
case 'mysqltest':
317320
case 'mysql':
318321
return sha1($type . ':' . $name);
@@ -343,9 +346,9 @@ public function buildUid($tpl, $value = null, $name = null, $type = null)
343346
case 'file':
344347
case 'filetest':
345348
if ($tpl instanceof Smarty) {
346-
return sha1(getcwd() . $this->normalizePath($this->smarty->getTemplateDir(0) . $name));
349+
return sha1($this->normalizePath($this->smarty->getTemplateDir(0) . $name));
347350
}
348-
return sha1(getcwd() . $tpl->source->filepath);
351+
return sha1($tpl->source->filepath);
349352
case 'mysqltest':
350353
case 'mysql':
351354
return sha1($type . ':' . $name);
@@ -357,21 +360,21 @@ public function buildUid($tpl, $value = null, $name = null, $type = null)
357360
}
358361

359362
/**
360-
* Normalize file path
363+
* Normalize path
364+
* - remove /./ and /../
365+
* - make it absolute
361366
*
362-
* @param string $path input path
363-
* @param bool $ds if true use system directory separator
367+
* @param string $path file path
364368
*
365369
* @return string
366370
*/
367-
public function normalizePath($path, $ds = false)
368-
{
369-
$path = str_replace(array('\\', '/./'), '/', $path);
370-
while ($path !== $new = preg_replace('#[^\.\/]+/\.\./#', '', $path)) {
371-
$path = $new;
371+
public function normalizePath($path) {
372+
if ($path[0] == '.') {
373+
$path = getcwd() . DS . $path;
372374
}
373-
if (DS !== '/' && $ds) {
374-
$path = str_replace('/', DS, $path);
375+
$path = str_replace($this->dsMap[DS][0], DS, $path);
376+
while (strrpos($path, $this->dsMap[DS][1]) !== false) {
377+
$path = preg_replace('#([\\\/][.][\\\/])|([\\\/][^\\\/]+[\\\/][.][.][\\\/])#', DS, $path);
375378
}
376379
return $path;
377380
}

UnitTests/CacheModify/ModifiedSince/HttpModifiedSinceTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public function testEnabledCached2()
123123
public function testEnabledCached3()
124124
{
125125

126+
//$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
126127
$_SERVER['SMARTY_PHPUNIT_HEADERS'] = array();
127128
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = gmdate('D, d M Y H:i:s', time() + 10) . ' GMT';
128129
$this->smarty->setCacheModifiedCheck(true);

UnitTests/ResourceTests/File/FileResourceTest.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function relative($path)
3636
public function testGetTemplateFilepath()
3737
{
3838
$tpl = $this->smarty->createTemplate('helloworld.tpl');
39-
$this->assertEquals("./templates/helloworld.tpl", str_replace('\\', '/', $tpl->source->filepath));
39+
$this->assertEquals($this->normalizePath("./templates/helloworld.tpl"), $tpl->source->filepath);
4040
}
4141

4242
public function testTemplateFileExists1()
@@ -407,10 +407,10 @@ public function testRelativityCwd()
407407

408408
$this->smarty->setCompileDir($dn . '/templates_c/');
409409
$this->smarty->setCacheDir($dn . '/cache/');
410+
chdir($dn . '/templates/relativity/theory/');
410411
$this->smarty->setTemplateDir(array(
411412
$dn . '/templates/',
412413
));
413-
chdir($dn . '/templates/relativity/theory/');
414414

415415
$map = array(
416416
'foo.tpl' => 'theory',
@@ -451,6 +451,9 @@ public function testRelativityPrecedence()
451451
);
452452

453453
chdir($dn . '/templates/relativity/theory/');
454+
$this->smarty->setTemplateDir(array(
455+
$dn . '/templates/relativity/theory/einstein/',
456+
));
454457
$this->_relativeMap($map, $cwd);
455458

456459
$map = array(
@@ -464,6 +467,9 @@ public function testRelativityPrecedence()
464467
);
465468

466469
chdir($dn . '/templates/relativity/theory/');
470+
$this->smarty->setTemplateDir(array(
471+
$dn . '/templates/relativity/theory/einstein/',
472+
));
467473
$this->_relativeMap($map, $cwd);
468474
}
469475

@@ -487,6 +493,9 @@ public function testRelativityRelRel()
487493
);
488494

489495
chdir($dn . '/templates/relativity/theory/einstein');
496+
$this->smarty->setTemplateDir(array(
497+
'../..',
498+
));
490499
$this->_relativeMap($map, $cwd);
491500

492501
$map = array(
@@ -497,6 +506,9 @@ public function testRelativityRelRel()
497506
);
498507

499508
chdir($dn . '/templates/relativity/theory/einstein/');
509+
$this->smarty->setTemplateDir(array(
510+
'../..',
511+
));
500512
$this->_relativeMap($map, $cwd);
501513

502514
$map = array(
@@ -512,10 +524,10 @@ public function testRelativityRelRel()
512524
'.././relativity.tpl' => 'relativity',
513525
);
514526

527+
chdir($dn . '/templates/relativity/theory/einstein/');
515528
$this->smarty->setTemplateDir(array(
516529
'..',
517530
));
518-
chdir($dn . '/templates/relativity/theory/einstein/');
519531
$this->_relativeMap($map, $cwd);
520532
}
521533

@@ -545,6 +557,9 @@ public function testRelativityRelRel1()
545557
);
546558

547559
chdir($dn . '/templates/relativity/theory/einstein/');
560+
$this->smarty->setTemplateDir(array(
561+
'..',
562+
));
548563
$this->_relativeMap($map, $cwd);
549564
}
550565
}

UnitTests/ResourceTests/File/IndexedFileResourceTest.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,35 @@ class IndexedFileResourceTest extends PHPUnit_Smarty
1212
public function setUp()
1313
{
1414
$this->setUpSmarty(__DIR__);
15-
$path = str_replace(array("\\", "/"), DS, dirname(__FILE__));
16-
$this->smarty->addTemplateDir($path . DS. 'templates_2');
15+
$this->smarty->addTemplateDir(__DIR__ . '/templates_2');
1716
// note that 10 is a string!
18-
$this->smarty->addTemplateDir($path . DS. 'templates_3', '10');
19-
$this->smarty->addTemplateDir($path . DS . 'templates_4', 'foo');
17+
$this->smarty->addTemplateDir(__DIR__ . '/templates_3', '10');
18+
$this->smarty->addTemplateDir(__DIR__ . '/templates_4', 'foo');
2019
}
2120

22-
protected function relative($path)
23-
{
24-
$path = str_replace(str_replace("\\", "/", dirname(__FILE__)), '.', str_replace("\\", "/", $path));
25-
26-
return $path;
27-
}
2821

2922
public function testGetTemplateFilepath()
3023
{
3124
$tpl = $this->smarty->createTemplate('dirname.tpl');
32-
$this->assertEquals("./templates/dirname.tpl", $this->relative($tpl->source->filepath));
25+
$this->assertEquals($this->normalizePath("./templates/dirname.tpl"), $tpl->source->filepath);
3326
}
3427

3528
public function testGetTemplateFilepathNumber()
3629
{
3730
$tpl = $this->smarty->createTemplate('[1]dirname.tpl');
38-
$this->assertEquals('./templates_2/dirname.tpl', $this->relative($tpl->source->filepath));
31+
$this->assertEquals($this->normalizePath('./templates_2/dirname.tpl'), $tpl->source->filepath);
3932
}
4033

4134
public function testGetTemplateFilepathNumeric()
4235
{
4336
$tpl = $this->smarty->createTemplate('[10]dirname.tpl');
44-
$this->assertEquals('./templates_3/dirname.tpl', $this->relative($tpl->source->filepath));
37+
$this->assertEquals($this->normalizePath('./templates_3/dirname.tpl'), $tpl->source->filepath);
4538
}
4639

4740
public function testGetTemplateFilepathName()
4841
{
4942
$tpl = $this->smarty->createTemplate('[foo]dirname.tpl');
50-
$this->assertEquals('./templates_4/dirname.tpl', $this->relative($tpl->source->filepath));
43+
$this->assertEquals($this->normalizePath('./templates_4/dirname.tpl'), $tpl->source->filepath);
5144
}
5245

5346
public function testFetch()

UnitTests/ResourceTests/Php/PhpResourceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function relative($path)
3636
public function testGetTemplateFilepath()
3737
{
3838
$tpl = $this->smarty->createTemplate('php:phphelloworld.php');
39-
$this->assertEquals("./templates/phphelloworld.php", str_replace('\\', '/', $tpl->source->filepath));
39+
$this->assertEquals($this->normalizePath("./templates/phphelloworld.php"), $tpl->source->filepath);
4040
}
4141

4242
/**

UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ public function testNotExistingChildBlock_024()
332332

333333
/**
334334
* @expectedException SmartyCompilerException
335-
* @expectedExceptionMessage Syntax error in template "./templates/025_parent.tpl"
336335
* @expectedExceptionMessage tag {$smarty.block.child} used outside {block} tags
337336
* test {$this->smarty.block.child} outside {block]
338337
*/
@@ -343,7 +342,6 @@ public function testSmartyBlockChildOutsideBlock_025()
343342

344343
/**
345344
* @expectedException SmartyCompilerException
346-
* @expectedExceptionMessage Syntax error in template "./templates/026_parent.tpl"
347345
* @expectedExceptionMessage tag {$smarty.block.parent} used outside {block} tags
348346
* test {$this->smarty.block.parent} outside {block]
349347
*/
@@ -354,7 +352,6 @@ public function testSmartyBlockParentOutsideBlock_026()
354352

355353
/**
356354
* @expectedException SmartyCompilerException
357-
* @expectedExceptionMessage Syntax error in template "./templates/027_parent.tpl"
358355
* @expectedExceptionMessage illegal {$smarty.block.parent} in parent template
359356
* test {$this->smarty.block.parent} in parent template
360357
*/

UnitTests/TemplateSource/TagTests/TemplateFunction/templates_c/1^422f9371d4d2d9de15c6d6b506a1de7f4d71063d_0.file.test_template_function_003.tpl.cache.php

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)