Skip to content

Commit

Permalink
Fix more parsed parameter types
Browse files Browse the repository at this point in the history
Related to the last commit.
Now fixing types for:
SolrCollapseFunction::setSize()
SolrDisMaxQuery::setPhraseSlop()
SolrDisMaxQuery::setQueryPhraseSlop()
SolrDisMaxQuery::setBigramPhraseSlop()
SolrDisMaxQuery::setTrigramPhraseSlop()
  • Loading branch information
bix0r committed Oct 13, 2023
1 parent e829934 commit 4d8668d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 6 deletions.
14 changes: 13 additions & 1 deletion src/php7/php_solr_collapse_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,23 @@ PHP_METHOD(SolrCollapseFunction, setSize)
{
solr_char_t *key = "size", *arg;
COMPAT_ARG_SIZE_T key_len = sizeof("size"), arg_len;
zval *tmp;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &tmp) == FAILURE) {
RETURN_NULL();
}

if (Z_TYPE_P(tmp) == IS_LONG) {
convert_to_string(tmp);
}

if (Z_TYPE_P(tmp) != IS_STRING) {
solr_throw_exception(solr_ce_SolrIllegalArgumentException, "Argument 1 must be an int", SOLR_ERROR_4000, SOLR_FILE_LINE_FUNC);
}

arg = Z_STRVAL_P(tmp);
arg_len = Z_STRLEN_P(tmp);

if (solr_solrfunc_update_string(getThis(), key, key_len, (solr_char_t *)arg, arg_len) == FAILURE) {
php_error_docref(NULL, E_ERROR, "Error assigning field");
RETURN_NULL();
Expand Down
60 changes: 56 additions & 4 deletions src/php7/php_solr_dismax_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,25 @@ PHP_METHOD(SolrDisMaxQuery, setPhraseSlop)
int add_result = -1;
solr_char_t *pvalue = NULL;
COMPAT_ARG_SIZE_T pvalue_len = 0;
zval *tmp;

if(zend_parse_parameters(ZEND_NUM_ARGS(), "s", &pvalue, &pvalue_len) == FAILURE)
if(zend_parse_parameters(ZEND_NUM_ARGS(), "z", &tmp) == FAILURE)
{
php_error_docref(NULL, E_WARNING, "Invalid parameters");
RETURN_NULL();
}

if (Z_TYPE_P(tmp) == IS_LONG) {
convert_to_string(tmp);
}

if (Z_TYPE_P(tmp) != IS_STRING) {
solr_throw_exception(solr_ce_SolrIllegalArgumentException, "Argument 1 must be an int", SOLR_ERROR_4000, SOLR_FILE_LINE_FUNC);
}

pvalue = Z_STRVAL_P(tmp);
pvalue_len = Z_STRLEN_P(tmp);

add_result = solr_add_or_set_normal_param(getThis(), pname, pname_len, pvalue, pvalue_len, 0);

if(add_result == FAILURE)
Expand All @@ -455,12 +468,25 @@ PHP_METHOD(SolrDisMaxQuery, setQueryPhraseSlop)
int add_result = -1;
solr_char_t *pvalue = NULL;
COMPAT_ARG_SIZE_T pvalue_len = 0;
zval *tmp;

if(zend_parse_parameters(ZEND_NUM_ARGS(), "s", &pvalue, &pvalue_len) == FAILURE)
if(zend_parse_parameters(ZEND_NUM_ARGS(), "z", &tmp) == FAILURE)
{
php_error_docref(NULL, E_WARNING, "Invalid parameters");
RETURN_NULL();
}

if (Z_TYPE_P(tmp) == IS_LONG) {
convert_to_string(tmp);
}

if (Z_TYPE_P(tmp) != IS_STRING) {
solr_throw_exception(solr_ce_SolrIllegalArgumentException, "Argument 1 must be an int", SOLR_ERROR_4000, SOLR_FILE_LINE_FUNC);
}

pvalue = Z_STRVAL_P(tmp);
pvalue_len = Z_STRLEN_P(tmp);

add_result = solr_add_or_set_normal_param(getThis(), pname, pname_len, pvalue, pvalue_len, 0);

if(add_result == FAILURE)
Expand Down Expand Up @@ -774,12 +800,25 @@ PHP_METHOD(SolrDisMaxQuery, setBigramPhraseSlop)
int add_result = -1;
solr_char_t *pvalue = NULL;
COMPAT_ARG_SIZE_T pvalue_len = 0;
zval *tmp;

if(zend_parse_parameters(ZEND_NUM_ARGS(), "s", &pvalue, &pvalue_len) == FAILURE)
if(zend_parse_parameters(ZEND_NUM_ARGS(), "z", &tmp) == FAILURE)
{
php_error_docref(NULL, E_WARNING, "Invalid parameters");
RETURN_NULL();
}

if (Z_TYPE_P(tmp) == IS_LONG) {
convert_to_string(tmp);
}

if (Z_TYPE_P(tmp) != IS_STRING) {
solr_throw_exception(solr_ce_SolrIllegalArgumentException, "Argument 1 must be an int", SOLR_ERROR_4000, SOLR_FILE_LINE_FUNC);
}

pvalue = Z_STRVAL_P(tmp);
pvalue_len = Z_STRLEN_P(tmp);

add_result = solr_add_or_set_normal_param(getThis(), pname, pname_len, pvalue, pvalue_len, 0);

if(add_result == FAILURE)
Expand Down Expand Up @@ -883,12 +922,25 @@ PHP_METHOD(SolrDisMaxQuery, setTrigramPhraseSlop)
int add_result = -1;
solr_char_t *pvalue = NULL;
COMPAT_ARG_SIZE_T pvalue_len = 0;
zval *tmp;

if(zend_parse_parameters(ZEND_NUM_ARGS(), "s", &pvalue, &pvalue_len) == FAILURE)
if(zend_parse_parameters(ZEND_NUM_ARGS(), "z", &tmp) == FAILURE)
{
php_error_docref(NULL, E_WARNING, "Invalid parameters");
RETURN_NULL();
}

if (Z_TYPE_P(tmp) == IS_LONG) {
convert_to_string(tmp);
}

if (Z_TYPE_P(tmp) != IS_STRING) {
solr_throw_exception(solr_ce_SolrIllegalArgumentException, "Argument 1 must be an int", SOLR_ERROR_4000, SOLR_FILE_LINE_FUNC);
}

pvalue = Z_STRVAL_P(tmp);
pvalue_len = Z_STRLEN_P(tmp);

add_result = solr_add_or_set_normal_param(getThis(), pname, pname_len, pvalue, pvalue_len, 0);

if(add_result == FAILURE)
Expand Down
18 changes: 17 additions & 1 deletion tests/203.solrquery_strict_types.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,25 @@ $query->setExpandRows('1');

echo $query . "\n";

try { $query->setStart(true); } catch (SolrIllegalArgumentException $e) { echo $e->getMessage(); }
try { $query->setStart(true); } catch (SolrIllegalArgumentException $e) { echo $e->getMessage() . "\n"; }

$collapse = new SolrCollapseFunction();
$collapse->setSize(1);

echo $collapse . "\n";

$d = new SolrDisMaxQuery('lucene');
$d->setPhraseSlop(2);
$d->setQueryPhraseSlop(3);
$d->setBigramPhraseSlop(4);
$d->setTrigramPhraseSlop(5);

echo $d . "\n";

--EXPECT--
q=lucene&start=1&rows=2&timeAllowed=300&group.offset=1&expand.rows=1
q=lucene&start=1anystring&rows=2&timeAllowed=300&group.offset=1&expand.rows=1
Argument 1 must be an int
{!collapse size=1}
q=lucene&defType=edismax&ps=2&qs=3&ps2=4&ps3=5

0 comments on commit 4d8668d

Please sign in to comment.