Skip to content

Commit 94e5842

Browse files
authored
Merge branch 'main' into port-python-tests
2 parents 25f1f55 + d512917 commit 94e5842

11 files changed

Lines changed: 920 additions & 673 deletions

File tree

src/couch/src/couch_doc.erl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ to_json_revisions(Options, Start, RevIds0) ->
6868
{<<"_revisions">>,
6969
{[
7070
{<<"start">>, Start},
71-
{<<"ids">>, [revid_to_str(R) || R <- RevIds]}
71+
{<<"ids">>, [revid_to_str(Start, R) || R <- RevIds]}
7272
]}}
7373
]
7474
end.
7575

76-
revid_to_str(RevId) when size(RevId) =:= 16 ->
76+
revid_to_str(Start, RevId) when Start =/= 0, byte_size(RevId) =:= 16 ->
7777
couch_util:to_hex_bin(RevId);
78-
revid_to_str(RevId) when is_binary(RevId) ->
78+
revid_to_str(Start, RevId) when is_integer(Start), Start >= 0, is_binary(RevId) ->
7979
RevId;
80-
revid_to_str(RevId) when is_list(RevId) ->
80+
revid_to_str(Start, RevId) when is_integer(Start), Start >= 0, is_list(RevId) ->
8181
list_to_binary(RevId).
8282

8383
rev_to_str({Pos, RevId}) ->
84-
<<(integer_to_binary(Pos))/binary, $-, (revid_to_str(RevId))/binary>>.
84+
<<(integer_to_binary(Pos))/binary, $-, (revid_to_str(Pos, RevId))/binary>>.
8585

8686
revs_to_strs([]) ->
8787
[];
@@ -188,13 +188,13 @@ from_json_obj({Props}, DbName) ->
188188
from_json_obj(_Other, _) ->
189189
throw({bad_request, "Document must be a JSON object"}).
190190

191-
parse_revid(RevId) when is_binary(RevId), size(RevId) =:= 32 ->
191+
parse_revid(Start, RevId) when Start =/= 0, is_binary(RevId), byte_size(RevId) =:= 32 ->
192192
binary:decode_hex(RevId);
193-
parse_revid(RevId) when is_list(RevId), length(RevId) =:= 32 ->
193+
parse_revid(Start, RevId) when Start =/= 0, is_list(RevId), length(RevId) =:= 32 ->
194194
binary:decode_hex(list_to_binary(RevId));
195-
parse_revid(RevId) when is_binary(RevId) ->
195+
parse_revid(Start, RevId) when is_integer(Start), Start >= 0, is_binary(RevId) ->
196196
RevId;
197-
parse_revid(RevId) when is_list(RevId) ->
197+
parse_revid(Start, RevId) when is_integer(Start), Start >= 0, is_list(RevId) ->
198198
?l2b(RevId).
199199

200200
parse_rev(Rev) when is_binary(Rev) ->
@@ -211,7 +211,7 @@ parse_rev(Rev) when is_list(Rev) ->
211211
{Pos, [$- | RevId]} ->
212212
try
213213
IntPos = list_to_integer(Pos),
214-
{IntPos, parse_revid(RevId)}
214+
{IntPos, parse_revid(IntPos, RevId)}
215215
catch
216216
error:badarg -> throw({bad_request, <<"Invalid rev format">>})
217217
end;
@@ -313,7 +313,7 @@ transfer_fields([{<<"_revisions">>, {Props}} | Rest], Doc, DbName) ->
313313
RevIds2 = lists:map(
314314
fun(RevId) ->
315315
try
316-
parse_revid(RevId)
316+
parse_revid(Start, RevId)
317317
catch
318318
error:function_clause ->
319319
throw({doc_validation, "RevId isn't a string"});

src/couch/test/eunit/couch_db_doc_tests.erl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,35 @@ add_revisions(Db, DocId, Rev, N) ->
115115
Rev,
116116
lists:seq(1, N)
117117
).
118+
119+
rev_to_str_test() ->
120+
?assertEqual(<<"0-0">>, couch_doc:rev_to_str({0, "0"})),
121+
?assertEqual(<<"0-0">>, couch_doc:rev_to_str({0, <<"0">>})),
122+
?assertEqual(<<"1-a">>, couch_doc:rev_to_str({1, <<"a">>})),
123+
Bytes = <<<<48>> || _ <- lists:seq(1, 16)>>,
124+
?assertEqual(<<"0-0000000000000000">>, couch_doc:rev_to_str({0, Bytes})),
125+
?assertEqual(<<"1-30303030303030303030303030303030">>, couch_doc:rev_to_str({1, Bytes})),
126+
?assertError(badarg, couch_doc:rev_to_str({a, b})),
127+
?assertError(function_clause, couch_doc:rev_to_str({-1, <<"x">>})),
128+
?assertError(function_clause, couch_doc:rev_to_str(foo)).
129+
130+
parse_rev_test() ->
131+
?assertEqual({1, <<"x">>}, couch_doc:parse_rev("1-x")),
132+
?assertEqual({1, <<"x">>}, couch_doc:parse_rev(<<"1-x">>)),
133+
?assertEqual({0, <<"y">>}, couch_doc:parse_rev("0-y")),
134+
?assertEqual({1234567890, <<"abc">>}, couch_doc:parse_rev("1234567890-abc")),
135+
?assertEqual(
136+
{0, <<"00000000000000000000000000000000">>},
137+
couch_doc:parse_rev("0-00000000000000000000000000000000")
138+
),
139+
?assertEqual(
140+
{1, <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>},
141+
couch_doc:parse_rev("1-00000000000000000000000000000000")
142+
),
143+
?assertThrow({bad_request, _}, couch_doc:parse_rev(foo)),
144+
?assertThrow({bad_request, _}, couch_doc:parse_rev("x-y")),
145+
?assertThrow({bad_request, _}, couch_doc:parse_rev("x")),
146+
?assertThrow({bad_request, _}, couch_doc:parse_rev("0")),
147+
?assertThrow({bad_request, _}, couch_doc:parse_rev("1")),
148+
?assertThrow({bad_request, _}, couch_doc:parse_rev("-")),
149+
?assertThrow({bad_request, _}, couch_doc:parse_rev("-0-1")).

src/couch/test/eunit/couch_doc_json_tests.erl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ from_json_success_cases() ->
9393
#doc{revs = {4, [<<"230234">>]}},
9494
"_rev stored in revs."
9595
},
96+
{
97+
{[{<<"_rev">>, <<"0-11111111111111111111111111111111">>}]},
98+
#doc{revs = {0, [<<"11111111111111111111111111111111">>]}},
99+
"_rev with start 0 stored in revs (local docs case)."
100+
},
101+
{
102+
{[{<<"_rev">>, <<"2-11111111111111111111111111111111">>}]},
103+
#doc{revs = {2, [<<17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17>>]}},
104+
"_rev with start 1 and size 32 stored in revs."
105+
},
96106
{
97107
{[{<<"soap">>, 35}]},
98108
#doc{body = {[{<<"soap">>, 35}]}},
@@ -287,7 +297,7 @@ from_json_error_cases() ->
287297
{[
288298
{<<"_revisions">>,
289299
{[
290-
{<<"start">>, 0},
300+
{<<"start">>, 1},
291301
{<<"ids">>, [<<"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">>]}
292302
]}}
293303
]},

src/couch_quickjs/patches/01-spidermonkey-185-mode.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
--- quickjs-master/quickjs.c 2025-11-15 08:52:50
2-
+++ quickjs/quickjs.c 2025-11-17 17:35:22
3-
@@ -31337,10 +31337,24 @@
1+
--- quickjs-master/quickjs.c 2025-11-22 06:10:55.000000000 -0500
2+
+++ quickjs/quickjs.c 2025-11-22 12:45:37.890107480 -0500
3+
@@ -31420,10 +31420,24 @@
44
if (s->token.val == TOK_FUNCTION ||
55
(token_is_pseudo_keyword(s, JS_ATOM_async) &&
66
peek_token(s, TRUE) == TOK_FUNCTION)) {

src/couch_quickjs/patches/02-test262-errors.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
--- quickjs-master/test262_errors.txt 2025-11-15 08:52:50
2-
+++ quickjs/test262_errors.txt 2025-11-17 17:35:22
1+
--- quickjs-master/test262_errors.txt 2025-11-22 06:10:55.000000000 -0500
2+
+++ quickjs/test262_errors.txt 2025-11-22 12:45:37.894107458 -0500
33
@@ -19,6 +19,8 @@
44
test262/test/language/expressions/compound-assignment/S11.13.2_A6.10_T1.js:24: Test262Error: #1: innerX === 2. Actual: 5
55
test262/test/language/expressions/compound-assignment/S11.13.2_A6.11_T1.js:24: Test262Error: #1: innerX === 2. Actual: 5

src/couch_quickjs/quickjs/Changelog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- micro optimizations (15% faster on bench-v8)
1+
- micro optimizations (30% faster on bench-v8)
22
- added resizable array buffers
33
- added ArrayBuffer.prototype.transfer
44
- added the Iterator object and methods

src/couch_quickjs/quickjs/libregexp-opcode.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ DEF(goto, 5)
3939
DEF(split_goto_first, 5)
4040
DEF(split_next_first, 5)
4141
DEF(match, 1)
42+
DEF(lookahead_match, 1)
43+
DEF(negative_lookahead_match, 1) /* must come after */
4244
DEF(save_start, 2) /* save start position */
4345
DEF(save_end, 2) /* save end position, must come after saved_start */
4446
DEF(save_reset, 3) /* reset save positions */
45-
DEF(loop, 5) /* decrement the top the stack and goto if != 0 */
46-
DEF(push_i32, 5) /* push integer on the stack */
47-
DEF(drop, 1)
47+
DEF(loop, 6) /* decrement the top the stack and goto if != 0 */
48+
DEF(push_i32, 6) /* push integer on the stack */
4849
DEF(word_boundary, 1)
4950
DEF(word_boundary_i, 1)
5051
DEF(not_word_boundary, 1)
@@ -58,10 +59,9 @@ DEF(range_i, 3) /* variable length */
5859
DEF(range32, 3) /* variable length */
5960
DEF(range32_i, 3) /* variable length */
6061
DEF(lookahead, 5)
61-
DEF(negative_lookahead, 5)
62-
DEF(push_char_pos, 1) /* push the character position on the stack */
63-
DEF(check_advance, 1) /* pop one stack element and check that it is different from the character position */
62+
DEF(negative_lookahead, 5) /* must come after */
63+
DEF(push_char_pos, 2) /* push the character position on the stack */
64+
DEF(check_advance, 2) /* pop one stack element and check that it is different from the character position */
6465
DEF(prev, 1) /* go to the previous char */
65-
DEF(simple_greedy_quant, 17)
6666

6767
#endif /* DEF */

0 commit comments

Comments
 (0)