[limb-svn] r5862 - in 3.x/trunk/limb/net: src tests/cases
svn at limb-project.com
svn at limb-project.com
Fri May 11 13:39:46 MSD 2007
Author: pachanga
Date: 2007-05-11 13:39:45 +0400 (Fri, 11 May 2007)
New Revision: 5862
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5862
Modified:
3.x/trunk/limb/net/src/lmbHttpRequest.class.php
3.x/trunk/limb/net/tests/cases/lmbHttpRequestTest.class.php
Log:
-- lmbHttpRequest :: getFiles() throws exception if submitted form has no enctype='multipart/form-data'
Modified: 3.x/trunk/limb/net/src/lmbHttpRequest.class.php
===================================================================
--- 3.x/trunk/limb/net/src/lmbHttpRequest.class.php 2007-05-11 04:23:53 UTC (rev 5861)
+++ 3.x/trunk/limb/net/src/lmbHttpRequest.class.php 2007-05-11 09:39:45 UTC (rev 5862)
@@ -84,6 +84,8 @@
function getFiles($key = null)
{
+ $this->_ensureMultipartFormData();
+
return $this->_get('files', $key);
}
@@ -205,6 +207,15 @@
{
return $this->toString();
}
+
+ protected function _ensureMultipartFormData()
+ {
+ if(!$this->hasPost() || $this->files)
+ return;
+
+ if(strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') === false)
+ throw new lmbException("Submitted form does not have enctype='multipart/form-data' attribute, no files loaded!");
+ }
}
?>
\ No newline at end of file
Modified: 3.x/trunk/limb/net/tests/cases/lmbHttpRequestTest.class.php
===================================================================
--- 3.x/trunk/limb/net/tests/cases/lmbHttpRequestTest.class.php 2007-05-11 04:23:53 UTC (rev 5861)
+++ 3.x/trunk/limb/net/tests/cases/lmbHttpRequestTest.class.php 2007-05-11 09:39:45 UTC (rev 5862)
@@ -125,6 +125,29 @@
$this->assertNull($request->get('form'));
}
+ function testGetFilesMultipartException()
+ {
+ $old = null;
+ if(isset($_SERVER['CONTENT_TYPE']))
+ $old = $_SERVER['CONTENT_TYPE'];
+
+ $_SERVER['CONTENT_TYPE'] = 'blah';
+
+ $request = new lmbHttpRequest('http://test.com');
+ $request->getFiles();//it's ok, no post request
+
+ $request->pretendPost();
+
+ try
+ {
+ $request->getFiles();
+ $this->assertTrue(false);
+ }
+ catch(lmbException $e){}
+
+ $_SERVER['CONTENT_TYPE'] = $old;
+ }
+
function testToString()
{
$files = array(
More information about the limb-svn
mailing list