diff options
Diffstat (limited to 'src/glob.c')
-rw-r--r-- | src/glob.c | 39 |
1 files changed, 22 insertions, 17 deletions
@@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2023 Robin Haberkorn + * Copyright (C) 2012-2024 Robin Haberkorn * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -225,17 +225,19 @@ teco_globber_compile_pattern(const gchar *pattern) *pout++ = '['; break; } + /* fall through: escape PCRE metacharacters */ + case '\\': + case '^': + case '$': + case '.': + case '|': + case '(': + case ')': + case '+': + case '{': + *pout++ = '\\'; /* fall through */ default: - /* - * For simplicity, all non-alphanumeric - * characters are escaped since they could - * be PCRE magic characters. - * g_regex_escape_string() is inefficient. - * character anyway. - */ - if (!g_ascii_isalnum(*pattern)) - *pout++ = '\\'; *pout++ = *pattern; break; } @@ -271,12 +273,13 @@ teco_globber_compile_pattern(const gchar *pattern) *pout++ = ']'; break; } - /* fall through */ - default: - if (!g_ascii_isalnum(*pattern)) - *pout++ = '\\'; + /* fall through: escape PCRE metacharacters */ + case '\\': + case '[': + *pout++ = '\\'; /* fall through */ case '-': + default: state = STATE_CLASS; *pout++ = *pattern; break; @@ -315,7 +318,8 @@ teco_state_glob_pattern_done(teco_machine_main_t *ctx, const teco_string_t *str, teco_qreg_t *glob_reg = teco_qreg_table_find(&teco_qreg_table_globals, "_", 1); g_assert(glob_reg != NULL); if (!glob_reg->vtable->undo_set_string(glob_reg, error) || - !glob_reg->vtable->set_string(glob_reg, filename, strlen(filename), error)) + !glob_reg->vtable->set_string(glob_reg, filename, strlen(filename), + teco_default_codepage(), error)) return NULL; } @@ -448,7 +452,7 @@ teco_state_glob_pattern_done(teco_machine_main_t *ctx, const teco_string_t *str, * when they should be in a register, the user will * have to edit that register anyway. */ -TECO_DEFINE_STATE_EXPECTFILE(teco_state_glob_pattern, +TECO_DEFINE_STATE_EXPECTGLOB(teco_state_glob_pattern, .expectstring.last = FALSE ); @@ -490,7 +494,8 @@ teco_state_glob_filename_done(teco_machine_main_t *ctx, const teco_string_t *str teco_qreg_t *glob_reg = teco_qreg_table_find(&teco_qreg_table_globals, "_", 1); g_assert(glob_reg != NULL); g_auto(teco_string_t) pattern_str = {NULL, 0}; - if (!glob_reg->vtable->get_string(glob_reg, &pattern_str.data, &pattern_str.len, error)) + if (!glob_reg->vtable->get_string(glob_reg, &pattern_str.data, &pattern_str.len, + NULL, error)) return NULL; if (teco_string_contains(&pattern_str, '\0')) { teco_error_qregcontainsnull_set(error, "_", 1, FALSE); |