diff --git a/src/mango/src/mango_idx_view.erl b/src/mango/src/mango_idx_view.erl index d1650e987cc..29895fbf9c6 100644 --- a/src/mango/src/mango_idx_view.erl +++ b/src/mango/src/mango_idx_view.erl @@ -417,7 +417,7 @@ range(_, _, LCmp, Low, HCmp, High) -> % beginsWith requires both a high and low bound range({[{<<"$beginsWith">>, Arg}]}, LCmp, Low, HCmp, High) -> {LCmp0, Low0, HCmp0, High0} = range({[{<<"$gte">>, Arg}]}, LCmp, Low, HCmp, High), - range({[{<<"$lte">>, <>}]}, LCmp0, Low0, HCmp0, High0); + range({[{<<"$lte">>, <>}]}, LCmp0, Low0, HCmp0, High0); range({[{<<"$lt">>, Arg}]}, LCmp, Low, HCmp, High) -> case range_pos(Low, Arg, High) of min -> diff --git a/src/mango/src/mango_selector.erl b/src/mango/src/mango_selector.erl index 93d3b10ca6c..24660e963f3 100644 --- a/src/mango/src/mango_selector.erl +++ b/src/mango/src/mango_selector.erl @@ -136,7 +136,10 @@ norm_ops({[{<<"$text">>, Arg}]}) when norm_ops({[{<<"$text">>, Arg}]}) -> ?MANGO_ERROR({bad_arg, '$text', Arg}); norm_ops({[{<<"$beginsWith">>, Arg}]} = Cond) when is_binary(Arg) -> - Cond; + case couch_util:validate_utf8(Arg) of + true -> Cond; + false -> ?MANGO_ERROR({bad_arg, '$beginsWith', Arg}) + end; % Not technically an operator but we pass it through here % so that this function accepts its own output. This exists % so that $text can have a field name value which simplifies diff --git a/src/mango/test/25-beginswith-test.py b/src/mango/test/25-beginswith-test.py index 3b5134b6514..919dcc661c4 100644 --- a/src/mango/test/25-beginswith-test.py +++ b/src/mango/test/25-beginswith-test.py @@ -54,7 +54,7 @@ def test_json_range(self): self.assertEqual(mrargs["start_key"], ["A"]) end_key_bytes = to_utf8_bytes(mrargs["end_key"]) - self.assertEqual(end_key_bytes, [b"A\xef\xbf\xbd", b""]) + self.assertEqual(end_key_bytes, [b"A\xf4\x8f\xbf\xbf", b""]) def test_compound_key(self): selector = {"name": "Eddie", "location": {"$beginsWith": "A"}} @@ -62,7 +62,7 @@ def test_compound_key(self): self.assertEqual(mrargs["start_key"], ["Eddie", "A"]) end_key_bytes = to_utf8_bytes(mrargs["end_key"]) - self.assertEqual(end_key_bytes, [b"Eddie", b"A\xef\xbf\xbd", b""]) + self.assertEqual(end_key_bytes, [b"Eddie", b"A\xf4\x8f\xbf\xbf", b""]) docs = self.db.find(selector) self.assertEqual(len(docs), 1) @@ -74,12 +74,12 @@ def test_sort(self): { "sort": ["location"], "start_key": [b"A"], - "end_key": [b"A\xef\xbf\xbd", b""], + "end_key": [b"A\xf4\x8f\xbf\xbf", b""], "direction": "fwd", }, { "sort": [{"location": "desc"}], - "start_key": [b"A\xef\xbf\xbd", b""], + "start_key": [b"A\xf4\x8f\xbf\xbf", b""], "end_key": [b"A"], "direction": "rev", }, @@ -97,7 +97,7 @@ def test_all_docs_range(self): self.assertEqual(mrargs["start_key"], "a") end_key_bytes = to_utf8_bytes(mrargs["end_key"]) - self.assertEqual(end_key_bytes, [b"a", b"\xef\xbf\xbd"]) + self.assertEqual(end_key_bytes, [b"a", b"\xf4\x8f\xbf\xbf"]) def test_no_index(self): selector = {"foo": {"$beginsWith": "a"}}