SFTP/Stream: fix issue with filenames with hash in them

This commit is contained in:
terrafrost 2015-12-23 07:41:30 -06:00
parent 57063f3604
commit 1be0ac9f7f
2 changed files with 26 additions and 0 deletions

View File

@ -171,7 +171,18 @@ class Net_SFTP_Stream
*/ */
function _parse_path($path) function _parse_path($path)
{ {
$orig = $path;
extract(parse_url($path) + array('port' => 22)); extract(parse_url($path) + array('port' => 22));
if (isset($query)) {
$path.= '?' . $query;
} elseif (preg_match('/(\?|\?#)$/', $orig)) {
$path.= '?';
}
if (isset($fragment)) {
$path.= '#' . $fragment;
} elseif ($orig[strlen($orig) - 1] == '#') {
$path.= '#';
}
if (!isset($host)) { if (!isset($host)) {
return false; return false;

View File

@ -22,6 +22,21 @@ class Functional_Net_SFTPStreamTest extends Functional_Net_SFTPTestCase
$this->assertSame(0, $this->sftp->size('fooo.txt')); $this->assertSame(0, $this->sftp->size('fooo.txt'));
} }
/**
* @group github778
*/
public function testFilenameWithHash()
{
$context = stream_context_create(array(
'sftp' => array('session' => $this->sftp),
));
$fp = fopen($this->buildUrl('te#st.txt'), 'wb', false, $context);
fputs($fp, 'zzzz');
fclose($fp);
$this->assertTrue(in_array('te#st.txt', $this->sftp->nlist()));
}
protected function buildUrl($suffix) protected function buildUrl($suffix)
{ {
return sprintf( return sprintf(