xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit 9dabbcca566f59eef00c4066378876d7af6ce50f

Warn user about incorrect string check in conds
In commands like :if or :elseif, lone `$VAR` or `"bla"` are converted to
bool by checking the string for being empty instead of by converting it
to an integer.

The bug will be fixed after making the release to let users a chance to
update their configurations.

Thanks to justpretending2.

Closes #1023 on GitHub.
Author: xaizek
Author date (UTC): 2024-10-17 11:45
Committer name: xaizek
Committer date (UTC): 2024-10-17 21:14
Parent(s): 6ff583b2eed79787f6693381e1c04e8c51df2d8d
Signing key: 99DC5E4DB05F6BE2
Tree: 221bdd89d917ce0bf5f4e78bd3682d2c93be6202
File Lines added Lines deleted
ChangeLog 5 0
src/cmd_handlers.c 25 0
tests/parsing/and_or.c 7 0
tests/parsing/asserts.h 24 0
File ChangeLog changed (mode: 100644) (index 3eab8148a..4e2101776)
71 71 Added WildBox highlight group. It can be used to set background of Added WildBox highlight group. It can be used to set background of
72 72 completion window. completion window.
73 73
74 Added a statusbar message and a dialog to warn about an upcoming fix for
75 strings in conditional expressions (e.g., `if $VAR` checks for `$VAR`
76 being non empty instead of converting it to an integer). Thanks to
77 justpretending2.
78
74 79 Don't draw right padding on a truncated rightmost column of a transposed Don't draw right padding on a truncated rightmost column of a transposed
75 80 ls-like view. ls-like view.
76 81
File src/cmd_handlers.c changed (mode: 100644) (index c9bc8b029..02dc65a8e)
... ... eval_if_condition(int cmd_id, const cmd_info_t *cmd_info)
3540 3540 } }
3541 3541 else else
3542 3542 { {
3543 if(parsing_result.value.type == VTYPE_STRING)
3544 {
3545 static int printed_warning;
3546
3547 ui_sb_errf("warning: checking for string length using a boolean context "
3548 "is a bug, update `%s` to use `!= ''` to avoid issues in the "
3549 "future", cmd_info->args);
3550 int num;
3551 if(!printed_warning && !read_int(cmd_info->args, &num))
3552 {
3553 printed_warning = 1;
3554
3555 int save_msg = curr_stats.save_msg;
3556 curr_stats.save_msg = 1;
3557 show_error_msgf("Condition evaluation",
3558 "The `%s` condition seems to be relying on a bug, please revise it "
3559 "to add `!= ''` to check for an empty string or `+ 0` to suppress "
3560 "this warning.\n"
3561 "(This is a once per session warning, `:messages` can contain "
3562 "more.)\n"
3563 "(The need for `+ 0` will be gone along with the bug and this "
3564 "warning in the next release.)", cmd_info->args);
3565 curr_stats.save_msg = save_msg;
3566 }
3567 }
3543 3568 result = var_to_bool(parsing_result.value); result = var_to_bool(parsing_result.value);
3544 3569 } }
3545 3570
File tests/parsing/and_or.c changed (mode: 100644) (index ea9cedcbb..832d72523)
... ... TEST(and_or_ignored_inside_strings)
85 85
86 86 TEST(strings_are_converted_to_integers) TEST(strings_are_converted_to_integers)
87 87 { {
88 ASSERT_BOOL_OK("''", 0);
89 /* The following checks must be inverted when the bug is fixed (breaks
90 * compatibility). */
91 ASSERT_BOOL_OK("'a'", 1);
92 ASSERT_BOOL_OK("'0'", 1);
93 ASSERT_BOOL_OK("'0'", 1);
94
88 95 ASSERT_OK("'a' && 'b' && 'c'", "0"); ASSERT_OK("'a' && 'b' && 'c'", "0");
89 96 ASSERT_OK("'0' && '0' && '0'", "0"); ASSERT_OK("'0' && '0' && '0'", "0");
90 97 ASSERT_OK("'1' && '2' && '4'", "1"); ASSERT_OK("'1' && '2' && '4'", "1");
File tests/parsing/asserts.h changed (mode: 100644) (index 60d4dec94..785a8941a)
38 38 } \ } \
39 39 while(0) while(0)
40 40
41 /* This should be a macro to see what test has failed. */
42 #define ASSERT_BOOL_OK(str, expected) \
43 do \
44 { \
45 parsing_result_t result = vle_parser_eval((str), /*interactive=*/0); \
46 assert_int_equal(PE_NO_ERROR, result.error); \
47 \
48 if(result.value.type != VTYPE_ERROR) \
49 { \
50 int bool_res = var_to_bool(result.value); \
51 if(expected) \
52 { \
53 assert_true(bool_res); \
54 } \
55 else \
56 { \
57 assert_false(bool_res); \
58 } \
59 } \
60 \
61 var_free(result.value); \
62 } \
63 while(0)
64
41 65 /* This should be a macro to see what test has failed. */ /* This should be a macro to see what test has failed. */
42 66 #define ASSERT_FAIL(str, error_code) \ #define ASSERT_FAIL(str, error_code) \
43 67 do \ do \
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master