Skip to content

Commit 76ae911

Browse files
authored
Merge pull request #1602 from UltimateHackingKeyboard/fix-tapkeyseq-hexcode
Fix tapkeyseq hexcode
2 parents 7e69891 + 76626ce commit 76ae911

5 files changed

Lines changed: 54 additions & 3 deletions

File tree

right/src/str_utils.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,15 @@ bool IsEnd(parser_context_t* ctx) {
136136
static void consumeWhite(parser_context_t* ctx)
137137
{
138138
while (!isEnd(ctx)) {
139-
while (*ctx->at <= 32 && !isEnd(ctx)) {
139+
// isEnd() may pop an exhausted parser context (e.g. an expandCodes/
140+
// template expansion), moving ctx->at to the parent's next token. It
141+
// must be checked *before* dereferencing ctx->at, otherwise a ctx->at++
142+
// here would step over that token's first character and drop it.
143+
while (!isEnd(ctx) && *ctx->at <= 32) {
140144
ctx->at++;
141145
}
142146
if (ctx->at[0] == '/' && ctx->at[1] == '/' && consumeCommentsAsWhite) {
143-
while (*ctx->at != '\n' && !isEnd(ctx)) {
147+
while (!isEnd(ctx) && *ctx->at != '\n') {
144148
ctx->at++;
145149
}
146150
}
@@ -322,7 +326,7 @@ void ConsumeAnyIdentifier(parser_context_t* ctx)
322326

323327
void ConsumeUntilDot(parser_context_t* ctx)
324328
{
325-
while(*ctx->at > 32 && *ctx->at != '.' && !isEnd(ctx)) {
329+
while(!isEnd(ctx) && *ctx->at > 32 && *ctx->at != '.') {
326330
ctx->at++;
327331
}
328332
if (*ctx->at != '.') {

right/src/test_suite/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ target_sources(${PROJECT_NAME} PRIVATE
1919
tests/test_sticky.c
2020
tests/test_playtime.c
2121
tests/test_transport.c
22+
tests/test_tapkeyseq.c
2223
)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "tests.h"
2+
3+
// Regression test for a template expansion bug.
4+
//
5+
// `tapKeySeq x y hexCodeOf(!) x y` would produce "xy21y" due to wrong ConsumeWhite/isEnd expansion.
6+
7+
static const test_action_t test_tapkeyseq_hexcode[] = {
8+
TEST_SET_MACRO("u",
9+
"tapKeySeq x y hexCodeOf(!) x y\n"
10+
),
11+
TEST_PRESS______("u"),
12+
TEST_DELAY__(20),
13+
// x
14+
TEST_EXPECT__________("x"),
15+
TEST_EXPECT__________(""),
16+
// y
17+
TEST_EXPECT__________("y"),
18+
TEST_EXPECT__________(""),
19+
// hexCodeOf(!) -> 2 1
20+
TEST_EXPECT__________("2"),
21+
TEST_EXPECT__________(""),
22+
TEST_EXPECT__________("1"),
23+
TEST_EXPECT__________(""),
24+
// x
25+
TEST_EXPECT__________("x"),
26+
TEST_EXPECT__________(""),
27+
// y (the final key of the sequence — the one the bug dropped)
28+
TEST_EXPECT__________("y"),
29+
TEST_EXPECT__________(""),
30+
TEST_RELEASE__U("u"),
31+
TEST_DELAY__(20),
32+
TEST_EXPECT__________(""),
33+
TEST_END()
34+
};
35+
36+
static const test_t tapkeyseq_tests[] = {
37+
{ .name = "tapkeyseq_hexcode", .actions = test_tapkeyseq_hexcode },
38+
};
39+
40+
const test_module_t TestModule_TapKeySeq = {
41+
.name = "TapKeySeq",
42+
.tests = tapkeyseq_tests,
43+
.testCount = sizeof(tapkeyseq_tests) / sizeof(tapkeyseq_tests[0])
44+
};

right/src/test_suite/tests/tests.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const test_module_t * const AllTestModules[] = {
1818
&TestModule_Sticky,
1919
&TestModule_Playtime,
2020
&TestModule_Transport,
21+
&TestModule_TapKeySeq,
2122
};
2223

2324
const uint16_t AllTestModulesCount = sizeof(AllTestModules) / sizeof(AllTestModules[0]);

right/src/test_suite/tests/tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ extern const test_module_t TestModule_ParserBenevolence;
3232
extern const test_module_t TestModule_Sticky;
3333
extern const test_module_t TestModule_Playtime;
3434
extern const test_module_t TestModule_Transport;
35+
extern const test_module_t TestModule_TapKeySeq;
3536

3637
#endif

0 commit comments

Comments
 (0)