do not retrieve content if it's too large
parent
9dc1656592
commit
b210c37d57
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
|||
|
||||
namespace LanguageServer\ContentRetriever;
|
||||
|
||||
use LanguageServer\ContentTooLargeException;
|
||||
use Sabre\Event\Promise;
|
||||
use function LanguageServer\uriToPath;
|
||||
|
||||
|
@ -19,6 +20,13 @@ class FileSystemContentRetriever implements ContentRetriever
|
|||
*/
|
||||
public function retrieve(string $uri): Promise
|
||||
{
|
||||
return Promise\resolve(file_get_contents(uriToPath($uri)));
|
||||
$limit = 150000;
|
||||
|
||||
$path = uriToPath($uri);
|
||||
$size = filesize($path);
|
||||
if ($size > $limit) {
|
||||
return Promise\reject(new ContentTooLargeException($uri, $size, $limit));
|
||||
}
|
||||
return Promise\resolve(file_get_contents($path));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,13 +105,7 @@ class PhpDocumentLoader
|
|||
public function load(string $uri): Promise
|
||||
{
|
||||
return coroutine(function () use ($uri) {
|
||||
|
||||
$limit = 150000;
|
||||
$content = yield $this->contentRetriever->retrieve($uri);
|
||||
$size = strlen($content);
|
||||
if ($size > $limit) {
|
||||
throw new ContentTooLargeException($uri, $size, $limit);
|
||||
}
|
||||
|
||||
if (isset($this->documents[$uri])) {
|
||||
$document = $this->documents[$uri];
|
||||
|
|
Loading…
Reference in New Issue