Skip to content

Commit 847589b

Browse files
committed
Fix more parsed parameter types
Related to the last commit. Now fixing types for: SolrCollapseFunction::setSize() SolrDisMaxQuery::setPhraseSlop() SolrDisMaxQuery::setQueryPhraseSlop() SolrDisMaxQuery::setBigramPhraseSlop() SolrDisMaxQuery::setTrigramPhraseSlop()
1 parent 8ebed91 commit 847589b

File tree

3 files changed

+86
-6
lines changed

3 files changed

+86
-6
lines changed

src/php7/php_solr_collapse_function.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,23 @@ PHP_METHOD(SolrCollapseFunction, setSize)
178178
{
179179
solr_char_t *key = "size", *arg;
180180
COMPAT_ARG_SIZE_T key_len = sizeof("size"), arg_len;
181+
zval *tmp;
181182

182-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE) {
183+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &tmp) == FAILURE) {
183184
RETURN_NULL();
184185
}
185186

187+
if (Z_TYPE_P(tmp) == IS_LONG) {
188+
convert_to_string(tmp);
189+
}
190+
191+
if (Z_TYPE_P(tmp) != IS_STRING) {
192+
solr_throw_exception(solr_ce_SolrIllegalArgumentException, "Argument 1 must be an int", SOLR_ERROR_4000, SOLR_FILE_LINE_FUNC);
193+
}
194+
195+
arg = Z_STRVAL_P(tmp);
196+
arg_len = Z_STRLEN_P(tmp);
197+
186198
if (solr_solrfunc_update_string(getThis(), key, key_len, (solr_char_t *)arg, arg_len) == FAILURE) {
187199
php_error_docref(NULL, E_ERROR, "Error assigning field");
188200
RETURN_NULL();

src/php7/php_solr_dismax_query.c

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,25 @@ PHP_METHOD(SolrDisMaxQuery, setPhraseSlop)
429429
int add_result = -1;
430430
solr_char_t *pvalue = NULL;
431431
COMPAT_ARG_SIZE_T pvalue_len = 0;
432+
zval *tmp;
432433

433-
if(zend_parse_parameters(ZEND_NUM_ARGS(), "s", &pvalue, &pvalue_len) == FAILURE)
434+
if(zend_parse_parameters(ZEND_NUM_ARGS(), "z", &tmp) == FAILURE)
434435
{
435436
php_error_docref(NULL, E_WARNING, "Invalid parameters");
436437
RETURN_NULL();
437438
}
439+
440+
if (Z_TYPE_P(tmp) == IS_LONG) {
441+
convert_to_string(tmp);
442+
}
443+
444+
if (Z_TYPE_P(tmp) != IS_STRING) {
445+
solr_throw_exception(solr_ce_SolrIllegalArgumentException, "Argument 1 must be an int", SOLR_ERROR_4000, SOLR_FILE_LINE_FUNC);
446+
}
447+
448+
pvalue = Z_STRVAL_P(tmp);
449+
pvalue_len = Z_STRLEN_P(tmp);
450+
438451
add_result = solr_add_or_set_normal_param(getThis(), pname, pname_len, pvalue, pvalue_len, 0);
439452

440453
if(add_result == FAILURE)
@@ -455,12 +468,25 @@ PHP_METHOD(SolrDisMaxQuery, setQueryPhraseSlop)
455468
int add_result = -1;
456469
solr_char_t *pvalue = NULL;
457470
COMPAT_ARG_SIZE_T pvalue_len = 0;
471+
zval *tmp;
458472

459-
if(zend_parse_parameters(ZEND_NUM_ARGS(), "s", &pvalue, &pvalue_len) == FAILURE)
473+
if(zend_parse_parameters(ZEND_NUM_ARGS(), "z", &tmp) == FAILURE)
460474
{
461475
php_error_docref(NULL, E_WARNING, "Invalid parameters");
462476
RETURN_NULL();
463477
}
478+
479+
if (Z_TYPE_P(tmp) == IS_LONG) {
480+
convert_to_string(tmp);
481+
}
482+
483+
if (Z_TYPE_P(tmp) != IS_STRING) {
484+
solr_throw_exception(solr_ce_SolrIllegalArgumentException, "Argument 1 must be an int", SOLR_ERROR_4000, SOLR_FILE_LINE_FUNC);
485+
}
486+
487+
pvalue = Z_STRVAL_P(tmp);
488+
pvalue_len = Z_STRLEN_P(tmp);
489+
464490
add_result = solr_add_or_set_normal_param(getThis(), pname, pname_len, pvalue, pvalue_len, 0);
465491

466492
if(add_result == FAILURE)
@@ -774,12 +800,25 @@ PHP_METHOD(SolrDisMaxQuery, setBigramPhraseSlop)
774800
int add_result = -1;
775801
solr_char_t *pvalue = NULL;
776802
COMPAT_ARG_SIZE_T pvalue_len = 0;
803+
zval *tmp;
777804

778-
if(zend_parse_parameters(ZEND_NUM_ARGS(), "s", &pvalue, &pvalue_len) == FAILURE)
805+
if(zend_parse_parameters(ZEND_NUM_ARGS(), "z", &tmp) == FAILURE)
779806
{
780807
php_error_docref(NULL, E_WARNING, "Invalid parameters");
781808
RETURN_NULL();
782809
}
810+
811+
if (Z_TYPE_P(tmp) == IS_LONG) {
812+
convert_to_string(tmp);
813+
}
814+
815+
if (Z_TYPE_P(tmp) != IS_STRING) {
816+
solr_throw_exception(solr_ce_SolrIllegalArgumentException, "Argument 1 must be an int", SOLR_ERROR_4000, SOLR_FILE_LINE_FUNC);
817+
}
818+
819+
pvalue = Z_STRVAL_P(tmp);
820+
pvalue_len = Z_STRLEN_P(tmp);
821+
783822
add_result = solr_add_or_set_normal_param(getThis(), pname, pname_len, pvalue, pvalue_len, 0);
784823

785824
if(add_result == FAILURE)
@@ -883,12 +922,25 @@ PHP_METHOD(SolrDisMaxQuery, setTrigramPhraseSlop)
883922
int add_result = -1;
884923
solr_char_t *pvalue = NULL;
885924
COMPAT_ARG_SIZE_T pvalue_len = 0;
925+
zval *tmp;
886926

887-
if(zend_parse_parameters(ZEND_NUM_ARGS(), "s", &pvalue, &pvalue_len) == FAILURE)
927+
if(zend_parse_parameters(ZEND_NUM_ARGS(), "z", &tmp) == FAILURE)
888928
{
889929
php_error_docref(NULL, E_WARNING, "Invalid parameters");
890930
RETURN_NULL();
891931
}
932+
933+
if (Z_TYPE_P(tmp) == IS_LONG) {
934+
convert_to_string(tmp);
935+
}
936+
937+
if (Z_TYPE_P(tmp) != IS_STRING) {
938+
solr_throw_exception(solr_ce_SolrIllegalArgumentException, "Argument 1 must be an int", SOLR_ERROR_4000, SOLR_FILE_LINE_FUNC);
939+
}
940+
941+
pvalue = Z_STRVAL_P(tmp);
942+
pvalue_len = Z_STRLEN_P(tmp);
943+
892944
add_result = solr_add_or_set_normal_param(getThis(), pname, pname_len, pvalue, pvalue_len, 0);
893945

894946
if(add_result == FAILURE)

tests/203.solrquery_strict_types.phpt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,25 @@ $query->setExpandRows('1');
2323

2424
echo $query . "\n";
2525

26-
try { $query->setStart(true); } catch (SolrIllegalArgumentException $e) { echo $e->getMessage(); }
26+
try { $query->setStart(true); } catch (SolrIllegalArgumentException $e) { echo $e->getMessage() . "\n"; }
27+
28+
$collapse = new SolrCollapseFunction();
29+
$collapse->setSize(1);
30+
31+
echo $collapse . "\n";
32+
33+
$d = new SolrDisMaxQuery('lucene');
34+
$d->setPhraseSlop(2);
35+
$d->setQueryPhraseSlop(3);
36+
$d->setBigramPhraseSlop(4);
37+
$d->setTrigramPhraseSlop(5);
38+
39+
echo $d . "\n";
40+
2741
--EXPECT--
2842
q=lucene&start=1&rows=2&timeAllowed=300&group.offset=1&expand.rows=1
2943
q=lucene&start=1anystring&rows=2&timeAllowed=300&group.offset=1&expand.rows=1
3044
Argument 1 must be an int
45+
{!collapse size=1}
46+
q=lucene&defType=edismax&ps=2&qs=3&ps2=4&ps3=5
3147

0 commit comments

Comments
 (0)