diff --git a/src/Product/SearchProvider.php b/src/Product/SearchProvider.php
index 6ad576f2e..9a28f269c 100644
--- a/src/Product/SearchProvider.php
+++ b/src/Product/SearchProvider.php
@@ -442,8 +442,14 @@ private function labelRangeFilters(array $facets)
foreach ($facet->getFilters() as $filter) {
$filterValue = $filter->getValue();
- $min = empty($filterValue[0]) ? $facet->getProperty('min') : $filterValue[0];
- $max = empty($filterValue[1]) ? $facet->getProperty('max') : $filterValue[1];
+ $min = $this->getNumericRangeBoundary(
+ isset($filterValue[0]) ? $filterValue[0] : null,
+ $facet->getProperty('min')
+ );
+ $max = $this->getNumericRangeBoundary(
+ isset($filterValue[1]) ? $filterValue[1] : null,
+ $facet->getProperty('max')
+ );
if ($facet->getType() === 'weight') {
$unit = Configuration::get('PS_WEIGHT_UNIT');
$filter->setLabel(
@@ -468,6 +474,27 @@ private function labelRangeFilters(array $facets)
}
}
+ /**
+ * Keep range labels resilient to malformed facet values coming from the URL.
+ *
+ * @param mixed $value
+ * @param mixed $fallback
+ *
+ * @return int|float|string
+ */
+ private function getNumericRangeBoundary($value, $fallback)
+ {
+ if (is_scalar($value) && is_numeric($value)) {
+ return $value;
+ }
+
+ if (is_scalar($fallback) && is_numeric($fallback)) {
+ return $fallback;
+ }
+
+ return 0;
+ }
+
/**
* This method generates a URL stub for each filter inside the given facets
* and assigns this stub to the filters.
diff --git a/tests/php/FacetedSearch/Product/SearchProviderTest.php b/tests/php/FacetedSearch/Product/SearchProviderTest.php
index a9adba7c0..ecd09f233 100644
--- a/tests/php/FacetedSearch/Product/SearchProviderTest.php
+++ b/tests/php/FacetedSearch/Product/SearchProviderTest.php
@@ -411,4 +411,14 @@ public function testRenderFacetsWithFacetsCollectionAndFilters()
)
);
}
+
+ public function testNumericRangeBoundaryFallsBackWhenValueIsMalformed()
+ {
+ $method = new \ReflectionMethod(SearchProvider::class, 'getNumericRangeBoundary');
+ $method->setAccessible(true);
+
+ $this->assertSame('12.50', $method->invoke($this->provider, '12.50', '1'));
+ $this->assertSame('1', $method->invoke($this->provider, '', '1'));
+ $this->assertSame(0, $method->invoke($this->provider, '', ''));
+ }
}