Merge pull request #21431 from nextcloud/search-filter-invalid-results
Filter out search results that have invalid encoding
This commit is contained in:
commit
ffc85ad614
|
@ -28,20 +28,28 @@ namespace OC\Core\Controller;
|
||||||
|
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http\JSONResponse;
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
|
use OCP\ILogger;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\ISearch;
|
use OCP\ISearch;
|
||||||
|
use OCP\Search\Result;
|
||||||
|
|
||||||
class SearchController extends Controller {
|
class SearchController extends Controller {
|
||||||
|
|
||||||
/** @var ISearch */
|
/** @var ISearch */
|
||||||
private $searcher;
|
private $searcher;
|
||||||
|
/** @var ILogger */
|
||||||
|
private $logger;
|
||||||
|
|
||||||
public function __construct(string $appName,
|
public function __construct(
|
||||||
|
string $appName,
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
ISearch $search) {
|
ISearch $search,
|
||||||
|
ILogger $logger
|
||||||
|
) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
|
|
||||||
$this->searcher = $search;
|
$this->searcher = $search;
|
||||||
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,6 +58,15 @@ class SearchController extends Controller {
|
||||||
public function search(string $query, array $inApps = [], int $page = 1, int $size = 30): JSONResponse {
|
public function search(string $query, array $inApps = [], int $page = 1, int $size = 30): JSONResponse {
|
||||||
$results = $this->searcher->searchPaged($query, $inApps, $page, $size);
|
$results = $this->searcher->searchPaged($query, $inApps, $page, $size);
|
||||||
|
|
||||||
|
$results = array_filter($results, function (Result $result) {
|
||||||
|
if (json_encode($result, JSON_HEX_TAG) === false) {
|
||||||
|
$this->logger->warning("Skipping search result due to invalid encoding: {type: " . $result->type . ", id: " . $result->id . "}");
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return new JSONResponse($results);
|
return new JSONResponse($results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue