Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do-not-merge(mango): fix derivation of upper bound for the range of $beginsWith #4829

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mango/src/mango_idx_view.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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">>, <<Arg/binary, 16#10FFFF>>}]}, LCmp0, Low0, HCmp0, High0);
range({[{<<"$lte">>, <<Arg/binary, 16#FFFF/utf8>>}]}, LCmp0, Low0, HCmp0, High0);
range({[{<<"$lt">>, Arg}]}, LCmp, Low, HCmp, High) ->
case range_pos(Low, Arg, High) of
min ->
Expand Down
5 changes: 4 additions & 1 deletion src/mango/src/mango_selector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/mango/test/25-beginswith-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ 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"<MAX>"])
self.assertEqual(end_key_bytes, [b"A\xf4\x8f\xbf\xbf", b"<MAX>"])

def test_compound_key(self):
selector = {"name": "Eddie", "location": {"$beginsWith": "A"}}
mrargs = self.get_mrargs(selector)

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"<MAX>"])
self.assertEqual(end_key_bytes, [b"Eddie", b"A\xf4\x8f\xbf\xbf", b"<MAX>"])

docs = self.db.find(selector)
self.assertEqual(len(docs), 1)
Expand All @@ -74,12 +74,12 @@ def test_sort(self):
{
"sort": ["location"],
"start_key": [b"A"],
"end_key": [b"A\xef\xbf\xbd", b"<MAX>"],
"end_key": [b"A\xf4\x8f\xbf\xbf", b"<MAX>"],
"direction": "fwd",
},
{
"sort": [{"location": "desc"}],
"start_key": [b"A\xef\xbf\xbd", b"<MAX>"],
"start_key": [b"A\xf4\x8f\xbf\xbf", b"<MAX>"],
"end_key": [b"A"],
"direction": "rev",
},
Expand All @@ -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"}}
Expand Down