diff --git a/phpseclib/Net/SFTP/Stream.php b/phpseclib/Net/SFTP/Stream.php index a62eb4ab..08d726ca 100644 --- a/phpseclib/Net/SFTP/Stream.php +++ b/phpseclib/Net/SFTP/Stream.php @@ -153,7 +153,18 @@ class 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 b596c4f8..2268989e 100644 --- a/tests/Functional/Net/SFTPStreamTest.php +++ b/tests/Functional/Net/SFTPStreamTest.php @@ -27,6 +27,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(