From 1be0ac9f7fe7e6c0543848283f3eb76ed79a4c06 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Wed, 23 Dec 2015 07:41:30 -0600 Subject: [PATCH] SFTP/Stream: fix issue with filenames with hash in them --- phpseclib/Net/SFTP/Stream.php | 11 +++++++++++ tests/Functional/Net/SFTPStreamTest.php | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/phpseclib/Net/SFTP/Stream.php b/phpseclib/Net/SFTP/Stream.php index 250c44e4..e374b9b9 100644 --- a/phpseclib/Net/SFTP/Stream.php +++ b/phpseclib/Net/SFTP/Stream.php @@ -171,7 +171,18 @@ class Net_SFTP_Stream */ function _parse_path($path) { + $orig = $path; 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)) { return false; diff --git a/tests/Functional/Net/SFTPStreamTest.php b/tests/Functional/Net/SFTPStreamTest.php index 6d731449..55115603 100644 --- a/tests/Functional/Net/SFTPStreamTest.php +++ b/tests/Functional/Net/SFTPStreamTest.php @@ -22,6 +22,21 @@ class Functional_Net_SFTPStreamTest extends Functional_Net_SFTPTestCase $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) { return sprintf(