~emersion/mrsh

0a3100e44328b2e41af5b3ef37c3ef61681a6b3b — Simon Ser 10 months ago 77dd6a2
shell/task: use word_to_pattern when running case clauses

This allows us to correctly handle quoted parts of the pattern.
1 files changed, 9 insertions(+), 3 deletions(-)

M shell/task/task.c
M shell/task/task.c => shell/task/task.c +9 -3
@@ 217,9 217,15 @@ static int run_case_clause(struct context *ctx, struct mrsh_case_clause *cc) {
			if (ret < 0) {
				return ret;
			}
			char *pattern_str = mrsh_word_str(*word_ptr);
			selected = fnmatch(pattern_str, word_str, 0) == 0;
			free(pattern_str);
			char *pattern = word_to_pattern(*word_ptr);
			if (pattern != NULL) {
				selected = fnmatch(pattern, word_str, 0) == 0;
				free(pattern);
			} else {
				char *str = mrsh_word_str(*word_ptr);
				selected = strcmp(str, word_str) == 0;
				free(str);
			}
			if (selected) {
				break;
			}