[Cs-content-commits] SF.net SVN: cs-content:[366] trunk/1.0
PHP Templating & Includes System
Brought to you by:
crazedsanity
|
From: <cra...@us...> - 2009-03-02 17:55:00
|
Revision: 366
http://cs-content.svn.sourceforge.net/cs-content/?rev=366&view=rev
Author: crazedsanity
Date: 2009-03-02 17:54:58 +0000 (Mon, 02 Mar 2009)
Log Message:
-----------
Set default section, handle request for relative filename w/leading slash.
/contentSystem.class.php:
* parse_section():
-- if we encounter "/" as the section, potentially use "DEFAULT_SECTION"
constant value instead of hard-coding "/content/index" (see #43)
/cs_fileSystem.class.php:
* filename2absolute():
-- special handling of requested file with single leading slash (treated
as a file within the relative path instead of absolute).
-- removed some extraneous commented-out debugging code.
/tests/testOfCSContent.php:
* __construct():
-- set constant for files directory
* test_siteConfig():
-- use constant for files directory
* test_genericPage():
-- use constant for files directory
* test_cs_fileSystem() [NEW]:
-- test handling of files with leading slashes, multiple slashes, dots,
etc. to ensure it works as expected.
-- this could stand to have many more tests...
Modified Paths:
--------------
trunk/1.0/contentSystem.class.php
trunk/1.0/cs_fileSystem.class.php
trunk/1.0/tests/testOfCSContent.php
Modified: trunk/1.0/contentSystem.class.php
===================================================================
--- trunk/1.0/contentSystem.class.php 2009-02-10 17:40:03 UTC (rev 365)
+++ trunk/1.0/contentSystem.class.php 2009-03-02 17:54:58 UTC (rev 366)
@@ -264,8 +264,8 @@
private function parse_section() {
//TODO::: this should be an OPTIONAL THING as to how to handle "/" (i.e. CSCONTENT_HANDLE_ROOTURL='content/index')
- if($this->section === 0 || is_null($this->section) || !strlen($this->section)) {
- $this->section = "content/index";
+ if(($this->section === 0 || is_null($this->section) || !strlen($this->section)) && defined('DEFAULT_SECTION')) {
+ $this->section = constant('DEFAULT_SECTION');
}
$myArr = split('/', $this->section);
Modified: trunk/1.0/cs_fileSystem.class.php
===================================================================
--- trunk/1.0/cs_fileSystem.class.php 2009-02-10 17:40:03 UTC (rev 365)
+++ trunk/1.0/cs_fileSystem.class.php 2009-03-02 17:54:58 UTC (rev 366)
@@ -413,14 +413,19 @@
$filename = $this->resolve_path_with_dots($filename);
- //see if it starts with a "/"...
+ //If it's a single filename beginning with a slash, strip the slash.
+ $x = array();
+ $numSlashes = preg_match_all('/\//', $filename, $x);
+ if(preg_match('/^\/[\w]/', $filename) && !preg_match('/^\/\./', $filename) && $numSlashes == 1) {
+ $filename = preg_replace('/^\//', '', $filename);
+ }
+
+
if(preg_match("/^\//", $filename)) {
$retval = $filename;
} else {
$retval=$this->realcwd .'/'. $filename;
$retval = $this->resolve_path_with_dots($retval);
- #debug_print(__METHOD__ .": realcwd=(". $this->realcwd .")");
- #$this->resolve_path_with_dots($retval);
}
if(!$this->check_chroot($retval, FALSE)) {
Modified: trunk/1.0/tests/testOfCSContent.php
===================================================================
--- trunk/1.0/tests/testOfCSContent.php 2009-02-10 17:40:03 UTC (rev 365)
+++ trunk/1.0/tests/testOfCSContent.php 2009-03-02 17:54:58 UTC (rev 366)
@@ -24,6 +24,9 @@
$this->gfObj = new cs_globalFunctions;
$this->gfObj->debugPrintOpt=1;
+
+ $filesDir = dirname(__FILE__) ."/files";
+ define('TEST_FILESDIR', $filesDir);
}//end __construct()
//-------------------------------------------------------------------------
@@ -179,7 +182,7 @@
//-------------------------------------------------------------------------
public function test_siteConfig() {
- $configFile = dirname(__FILE__) .'/files/sampleConfig.xml';
+ $configFile = constant('TEST_FILESDIR') .'/sampleConfig.xml';
$varPrefix = preg_replace("/:/", "_", __METHOD__ ."-");
$sc = new cs_siteConfig($configFile, 'main', $varPrefix);
@@ -247,7 +250,7 @@
//-------------------------------------------------------------------------
function test_genericPage() {
- $filesDir = dirname(__FILE__) .'/files';
+ $filesDir = constant('TEST_FILESDIR');
$page = new cs_genericPage(false, $filesDir .'/templates/main.shared.tmpl', false);
$fs = new cs_fileSystem($filesDir .'/templates');
@@ -302,6 +305,36 @@
+ //-------------------------------------------------------------------------
+ function test_cs_fileSystem() {
+ $fs = new cs_fileSystem(constant('TEST_FILESDIR'));
+
+ $list = array(
+ 'slashTest' => array('/sampleConfig.xml', 'sampleConfig.xml'),
+ 'slashtest2' => array('/templates/content.shared.tmpl', 'templates/content.shared.tmpl'),
+ 'pathWithDots' => array('templates/.././sampleConfig.xml', '/templates/.././sampleConfig.xml'),
+ 'multiSlashes' => array('////sampleConfig.xml', '///sampleConfig.xml', '/templates///////content.shared.tmpl/../templates/content.shared.tmpl')
+ );
+
+ foreach($list as $testName=>$files) {
+ foreach($files as $filename) {
+ $gotException=false;
+ try {
+ $data = $fs->ls('/sampleConfig.xml');
+ }
+ catch(exception $e) {
+ $gotException=true;
+ }
+
+ $this->assertFalse($gotException, "Failed test '". $testName ."'");
+ }
+ }
+
+ }//end test_cs_fileSystem()
+ //-------------------------------------------------------------------------
+
+
+
}//end TestOfCSContent
//=============================================================================
?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|