Commit 761daf4d authored by Spencer Rinehart's avatar Spencer Rinehart Committed by Markus Kalkbrenner

Escape the phrases in a range query. (#565)

* Escape the phrases in a range query.

In order to prevent query injection, the helper methods should escape
the phrases.  Otherwise you could end up with something like
rangeQuery('1', '2] someOtherField:[* TO *') and leak information, etc.

* Update changelog for escape-range changes.
parent 39b99b39
...@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ...@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Isolated search components from the select query type and made them re-usable - Isolated search components from the select query type and made them re-usable
- BC break: Suggester component is now compatible to Solr v6/7 (the existing one was renamed to Spellcheck) - BC break: Suggester component is now compatible to Solr v6/7 (the existing one was renamed to Spellcheck)
- BC break: Suggester query type is now compatible to Solr v6/7 (the existing one was renamed to Spellcheck) - BC break: Suggester query type is now compatible to Solr v6/7 (the existing one was renamed to Spellcheck)
- Prevented query injection inside range queries
- Lots of source code re-structuring and clean-up - Lots of source code re-structuring and clean-up
### Removed ### Removed
......
...@@ -180,6 +180,9 @@ class Helper ...@@ -180,6 +180,9 @@ class Helper
$to = '*'; $to = '*';
} }
$from = $this->escapePhrase($from);
$to = $this->escapePhrase($to);
if ($inclusive) { if ($inclusive) {
return $field.':['.$from.' TO '.$to.']'; return $field.':['.$from.' TO '.$to.']';
} }
......
...@@ -28,12 +28,12 @@ class HelperTest extends TestCase ...@@ -28,12 +28,12 @@ class HelperTest extends TestCase
public function testRangeQueryInclusive() public function testRangeQueryInclusive()
{ {
$this->assertEquals( $this->assertEquals(
'field:[1 TO 2]', 'field:["1" TO "2"]',
$this->helper->rangeQuery('field', 1, 2) $this->helper->rangeQuery('field', 1, 2)
); );
$this->assertSame( $this->assertSame(
'store:[45,-94 TO 46,-93]', 'store:["45,-94" TO "46,-93"]',
$this->helper->rangeQuery('store', '45,-94', '46,-93') $this->helper->rangeQuery('store', '45,-94', '46,-93')
); );
} }
...@@ -41,12 +41,12 @@ class HelperTest extends TestCase ...@@ -41,12 +41,12 @@ class HelperTest extends TestCase
public function testRangeQueryExclusive() public function testRangeQueryExclusive()
{ {
$this->assertSame( $this->assertSame(
'field:{1 TO 2}', 'field:{"1" TO "2"}',
$this->helper->rangeQuery('field', 1, 2, false) $this->helper->rangeQuery('field', 1, 2, false)
); );
$this->assertSame( $this->assertSame(
'store:{45,-94 TO 46,-93}', 'store:{"45,-94" TO "46,-93"}',
$this->helper->rangeQuery('store', '45,-94', '46,-93', false) $this->helper->rangeQuery('store', '45,-94', '46,-93', false)
); );
} }
...@@ -54,12 +54,12 @@ class HelperTest extends TestCase ...@@ -54,12 +54,12 @@ class HelperTest extends TestCase
public function testRangeQueryInclusiveNullValues() public function testRangeQueryInclusiveNullValues()
{ {
$this->assertSame( $this->assertSame(
'field:[1 TO *]', 'field:["1" TO "*"]',
$this->helper->rangeQuery('field', 1, null) $this->helper->rangeQuery('field', 1, null)
); );
$this->assertSame( $this->assertSame(
'store:[* TO 46,-93]', 'store:["*" TO "46,-93"]',
$this->helper->rangeQuery('store', null, '46,-93') $this->helper->rangeQuery('store', null, '46,-93')
); );
} }
...@@ -67,12 +67,12 @@ class HelperTest extends TestCase ...@@ -67,12 +67,12 @@ class HelperTest extends TestCase
public function testRangeQueryExclusiveNullValues() public function testRangeQueryExclusiveNullValues()
{ {
$this->assertSame( $this->assertSame(
'field:{1 TO *}', 'field:{"1" TO "*"}',
$this->helper->rangeQuery('field', 1, null, false) $this->helper->rangeQuery('field', 1, null, false)
); );
$this->assertSame( $this->assertSame(
'store:{* TO 46,-93}', 'store:{"*" TO "46,-93"}',
$this->helper->rangeQuery('store', null, '46,-93', false) $this->helper->rangeQuery('store', null, '46,-93', false)
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment