Skip to content

Commit

Permalink
Merge pull request #1276 from kinow/fix-1275
Browse files Browse the repository at this point in the history
Do not treat 0 as boolean value in the REST controller
  • Loading branch information
osma authored Feb 17, 2022
2 parents b30ac87 + 5037842 commit 5c3cc4d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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

0 comments on commit 5c3cc4d

Please sign in to comment.