From a4d254c6ecfac54358e8afebc90106022c1d108b Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 15 Jan 2023 16:08:08 +0300 Subject: [PATCH] Ticket #4429: multi-line search is buggy. Revert "Ticket #400: support multi-line search." This reverts commit e370818c09bbbb2e2bd445969d57e48ce7b76a05. Update doc/README. Signed-off-by: Andrew Borodin --- doc/NEWS | 1 - lib/search/regex.c | 6 +- tests/lib/search/Makefile.am | 4 - tests/lib/search/regex_multiline_str.c | 155 --------------------------------- 4 files changed, 3 insertions(+), 163 deletions(-) delete mode 100644 tests/lib/search/regex_multiline_str.c diff --git a/doc/NEWS b/doc/NEWS index 9cc68045d..c62ea7ac0 100644 --- a/doc/NEWS +++ b/doc/NEWS @@ -8,7 +8,6 @@ Version 4.8.29 * "Using shell patterns" * Continue copy after interrupt (#4409) * Restore menu accelerator for "Sort order": back to "S"; change menu accelerator for "SFTP link" to "N" (#4373) - * Implement multi-line search in regex mode using '\n' character (#400) * Add support for cross-compilation with PERL path different between --build and --host (#4399) * Bootstrap with autotools providing direct support for Apple M1 * Port mc.ext to INI format and rename to mc.ext.ini (#4141, #3742, #3191) diff --git a/lib/search/regex.c b/lib/search/regex.c index d8e79375d..07b68331b 100644 --- a/lib/search/regex.c +++ b/lib/search/regex.c @@ -897,7 +897,7 @@ mc_search__run_regex (mc_search_t * lc_mc_search, const void *user_data, { while (TRUE) { - int current_chr = '\0'; /* stop search symbol */ + int current_chr = '\n'; /* stop search symbol */ ret = lc_mc_search->search_fn (user_data, current_pos, ¤t_chr); @@ -916,7 +916,7 @@ mc_search__run_regex (mc_search_t * lc_mc_search, const void *user_data, g_string_append_c (lc_mc_search->regex_buffer, (char) current_chr); - if ((char) current_chr == '\0' || virtual_pos >= end_search) + if ((char) current_chr == '\n' || virtual_pos > end_search) break; } } @@ -935,7 +935,7 @@ mc_search__run_regex (mc_search_t * lc_mc_search, const void *user_data, current_pos++; - if (current_pos >= end_search) + if (current_chr == '\n' || current_pos > end_search) break; } diff --git a/tests/lib/search/Makefile.am b/tests/lib/search/Makefile.am index 70e7ba8c3..d01c0dc94 100644 --- a/tests/lib/search/Makefile.am +++ b/tests/lib/search/Makefile.am @@ -20,7 +20,6 @@ TESTS = \ hex_translate_to_regex \ regex_replace_esc_seq \ regex_process_escape_sequence \ - regex_multiline_str \ translate_replace_glob_to_regex check_PROGRAMS = $(TESTS) @@ -34,9 +33,6 @@ regex_replace_esc_seq_SOURCES = \ regex_process_escape_sequence_SOURCES = \ regex_process_escape_sequence.c -regex_multiline_str_SOURCES = \ - regex_multiline_str.c - translate_replace_glob_to_regex_SOURCES = \ translate_replace_glob_to_regex.c diff --git a/tests/lib/search/regex_multiline_str.c b/tests/lib/search/regex_multiline_str.c deleted file mode 100644 index 36d8d8f93..000000000 --- a/tests/lib/search/regex_multiline_str.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - libmc - checks search functions - - Copyright (C) 2022 - Free Software Foundation, Inc. - - Written by: - Steef Boerrigter , 2022 - - This file is part of the Midnight Commander. - - The Midnight Commander is free software: you can redistribute it - and/or modify it under the terms of the GNU General Public License as - published by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - The Midnight Commander is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ - -#define TEST_SUITE_NAME "lib/search/search" - -#include "tests/mctest.h" - -#include "search.c" /* for testing static functions */ - -/* --------------------------------------------------------------------------------------------- */ - -/* @DataSource("test_regex_multiline_str_ds") */ -/* *INDENT-OFF* */ -static const struct test_regex_multiline_str_ds -{ - const mc_search_type_t type; - const char *buffer; - const char *search_str; - const gboolean retval; -} test_regex_multiline_str_ds[] = -{ - { /* 1. */ - MC_SEARCH_T_NORMAL, - "abcdefgh", - "nope", - FALSE - }, - { /* 2. */ - MC_SEARCH_T_NORMAL, - "abcdefgh", - "def", - TRUE - }, - { /* 3. */ - MC_SEARCH_T_NORMAL, - "abcdefgh", - "z", - FALSE - }, - { /* 4. */ - MC_SEARCH_T_NORMAL, - "abcd \tefgh", - "\t ", - TRUE - }, - { /* 5. multiline */ - MC_SEARCH_T_NORMAL, - "abcd\ne\nfgh", - "\ne\nf", - TRUE - }, - { /* 6. */ - MC_SEARCH_T_NORMAL, - "abcd\nefgh", - "d\ne", - TRUE - }, - { /* 7. mc-4.8.28 fails this edge condition */ - MC_SEARCH_T_NORMAL, - "abcdefgh\n", - "\n", - TRUE - }, - { /* 8. mc-4.8.28 fails this edge condition */ - MC_SEARCH_T_NORMAL, - "abcdefgh\n", - "\n\n", - FALSE - }, - { /* 9. regex including newline */ - MC_SEARCH_T_REGEX, - "abcd\nefgh", - "abc[c-e]\nef", - TRUE - }, - { /* 10. regex's newline support */ - MC_SEARCH_T_REGEX, - "abcd\nefgh", - "abc[c-e]\\nef", - TRUE - }, -}; -/* *INDENT-ON* */ - -/* @Test(dataSource = "test_regex_multiline_str_ds") */ -/* *INDENT-OFF* */ -START_PARAMETRIZED_TEST (test_regex_multiline_str, test_regex_multiline_str_ds) -/* *INDENT-ON* */ -{ - /* given */ - mc_search_t *s; - gboolean retval; - - s = mc_search_new (data->buffer, NULL); - s->is_case_sensitive = FALSE; - s->search_type = data->type; - - /* when */ - retval = mc_search (data->search_str, DEFAULT_CHARSET, data->buffer, s->search_type); - - /* then */ - if (data->retval) - { - mctest_assert_true (retval); - } - else - { - mctest_assert_false (retval); - } - - mc_search_free (s); -} -/* *INDENT-OFF* */ -END_PARAMETRIZED_TEST -/* *INDENT-ON* */ - -/* --------------------------------------------------------------------------------------------- */ - -int -main (void) -{ - TCase *tc_core; - - tc_core = tcase_create ("Core"); - - /* Add new tests here: *************** */ - mctest_add_parameterized_test (tc_core, test_regex_multiline_str, test_regex_multiline_str_ds); - /* *********************************** */ - - return mctest_run_all (tc_core); -} - -/* --------------------------------------------------------------------------------------------- */ -- 2.11.4.GIT