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

Do not treat 0 as boolean value in the REST controller #1276

Merged
merged 1 commit into from
Feb 17, 2022
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
4 changes: 2 additions & 2 deletions model/ConceptSearchParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public function getArrayClass()
return null;
}

public function getSearchTerm()
public function getSearchTerm() : string
{
$term = $this->request->getQueryParamRaw('q') ? $this->request->getQueryParamRaw('q') : $this->request->getQueryParamRaw('query');
if (!$term && $this->rest)
if ((!isset($term) || strlen(trim($term)) === 0) && $this->rest)
$term = $this->request->getQueryParamRaw('label');
$term = trim($term); // surrounding whitespace is not considered significant
$term = Normalizer::normalize( $term, Normalizer::FORM_C ); //Normalize decomposed unicode characters #1184
Expand Down
20 changes: 20 additions & 0 deletions tests/ConceptSearchParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ public function testGetSearchTerm() {
$this->assertEquals('test', $params->getSearchTerm());
}

/**
* For https://github.com/NatLibFi/Skosmos/issues/1275, to verify
* that querying for `0` (zero) does not evaluate it as a boolean
* value, causing issues in the SKOSMOS search functionality.
*
* @covers ConceptSearchParameters::getSearchTerm
*/
public function testGetSearchTermZeroes() {
$params = new ConceptSearchParameters($this->request, new GlobalConfig('/../tests/testconfig.ttl'), true);
$this->assertEquals('', $params->getSearchTerm());
$this->request->method('getQueryParamRaw')->will(
$this->returnValueMap([
['q', '0'],
['query', '0'],
['label', '10']
])
);
$this->assertEquals('0', $params->getSearchTerm());
}

/**
* @covers ConceptSearchParameters::getTypeLimit
* @covers ConceptSearchParameters::getDefaultTypeLimit
Expand Down