DistributedProofreaders / guiguts

Perl/Tk text editor designed for editing and formatting public domain material for inclusion at Project Gutenberg
GNU General Public License v2.0
9 stars 10 forks source link

$2 is still replaced by a \n during search & replace #605

Closed okrick closed 3 years ago

okrick commented 3 years ago

Describe the bug A "$2" sequence is replaced by a "\n" during a regex S&R where the "$2" sequence is part of the found text replaced by quoting.

To Reproduce Steps to reproduce the behavior:

  1. Open Guiguts
  2. Open the Search->Search & Replace
  3. Search for a text string within a (quote) parenthesis.
  4. Set $1 as part of the Replace string
  5. If the found text contains a "$2" text string then that part of the replacement is a "\n"

Expected behavior I expect a '$2' string to be replaced by a '$2' string.

Environment

This file has two instances of $2 which were replaced by \n: https://www.pgdp.net/projects/projectID47b9ed7181d66/projectID47b9ed7181d66.zip

Additional context Sorry, I thought this was fixed. I looked for the old bug report but didn't find it.

windymilla commented 3 years ago

Hi Rick - I thought it was fixed too. The previous reports were #121 and #308.

I have just tried recreating it using release 1.2.4, but I cannot make it go wrong. I also tried the example you included in #121 but it didn't go wrong - does this look like the problem you are reporting?

Search: <table((.|\n)+?)</table> Replace: <div class="center"><div class="ilb">\n<table$1</table>\n</div></div>

Text:

<hr />
<table class="p1" summary="Errors in the books">
  <tr>
    <td class="tdl">An overstatement of net income of</td>
    <td class="tdr">$2,721,068</td></tr>
  <tr>
    <td class="tdl">A mischarge of worn-out equipment to profit and loss of</td>
    <td class="tdr">2,843,596</td></tr>
</table>
<hr />

So, I can think of two possibilities. Either, there is some odd situation in your latest file that is still triggering the bug even though the original bug is fixed. Or, you were accidentally running a different release (not 1.2.4) for some of your work, and the problem happened using that.

  1. Please can you check that you are definitely using 1.2.4 (should be dated approx 8th Feb)
  2. Load your projectID47b9ed7181d66.txt file in, and do a search/replace that causes the problem.
  3. Include the search and replace terms in a message here, as well as telling me which line number to start searching from.

Hopefully, this is just a mix-up, but if not, I'll look into it again once I get your clarification. Thanks

okrick commented 3 years ago
  1. The version file is guiguts-win-1.2.4.zip and the directory inside is dated 8 February 2021.
  2. Loaded the file.
  3. Search term is

/*((\n|.)+?)*/

  1. Replace term is

.ta hr s='' w=none$1.ta-

  1. line 11876 was before

12,546 nurses--Total cost $2,230,200.00

  1. after replacing

12,546 nurses--Total cost ,230,200.00

Cheers,

windymilla commented 3 years ago

Thanks - definitely goes wrong - I'll look into why that is

windymilla commented 3 years ago

Doh! I only made the code give special treatment to the first dollar sign in the found text, instead of all dollars. Sorry.

If you want to fix your code, edit SearchReplaceMenu.pm which is in lib/Guiguts Find line 725, which should say

        $match       =~ s/\$/\\\$/;

and add the letter "g" for "global" just before the semicolon at the end, i.e.

        $match       =~ s/\$/\\\$/g;

I'll put this fix in 1.3 of course.