Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vocabulary search using "0" as the search string #1267

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion model/ConceptSearchParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getArrayClass()

public function getSearchTerm() : string
{
$term = $this->request->getQueryParamRaw('q') ? $this->request->getQueryParamRaw('q') : $this->request->getQueryParamRaw('query');
$term = $this->request->getQueryParamRaw('q') !== null ? $this->request->getQueryParamRaw('q') : $this->request->getQueryParamRaw('query');
if ((!isset($term) || strlen(trim($term)) === 0) && $this->rest)
$term = $this->request->getQueryParamRaw('label');
$term = trim($term); // surrounding whitespace is not considered significant
Expand Down
1 change: 0 additions & 1 deletion model/sparql/GenericSparql.php
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,6 @@ protected function generateConceptSearchQueryInner($term, $lang, $searchLang, $p
}
$hitgroup
EOQ;

return $query;
}
/**
Expand Down
11 changes: 11 additions & 0 deletions tests/ConceptSearchParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ public function testGetSearchTerm() {
$this->assertEquals('test', $params->getSearchTerm());
}

/**
* @covers ConceptSearchParameters::getSearchTerm
* Is created particularly for searches not using REST
*/
public function testSearchTermWithoutRest() {
$params = new ConceptSearchParameters($this->request, new GlobalConfig('/../tests/testconfig.ttl'), false);
$this->request->method('getQueryParamRaw')->will($this->returnValue('0'));
$this->assertEquals('0*', $params->getSearchTerm());
}

/**
* For https://github.com/NatLibFi/Skosmos/issues/1275, to verify
* that querying for `0` (zero) does not evaluate it as a boolean
Expand Down Expand Up @@ -250,4 +260,5 @@ public function testGetAdditionalFields() {
$params = new ConceptSearchParameters($this->request, new GlobalConfig('/../tests/testconfig.ttl'));
$this->assertEquals(array('broader', 'prefLabel'), $params->getAdditionalFields());
}

}
4 changes: 2 additions & 2 deletions tests/RestControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public function testSearchJsonLdWithAdditionalFields() {
/**
* Data provider for testSearchWithZero test.
*/
public function testSearchWithZeroData(): array {
public function provideSearchWithZeroData(): array {
return [
['0', true],
['1', true],
Expand All @@ -328,7 +328,7 @@ public function testSearchWithZeroData(): array {

/**
* @covers RestController::search
* @dataProvider testSearchWithZeroData
* @dataProvider provideSearchWithZeroData
* @param $query string the search query
* @param $isSuccess bool whether the request must succeed or fail
*/
Expand Down