Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When replacing text if your replace string includes \b it inserts a backspace (as well as some other escape characters) #197

Closed
JVimes opened this issue Dec 1, 2014 · 6 comments

Comments

@JVimes
Copy link
Contributor

JVimes commented Dec 1, 2014

From Justin....@gmail.com on August 07, 2013 09:01:08

What steps will reproduce the problem? 1. Create a text file with some text
2. Enter search string that will match text in that file
3. Replace with C:\test\bin What is the expected output? What do you see instead? Expected output: C:\test\bin
Actual output: C:\test(backspace character)in What version of the product are you using? On what operating system? v2.7.0
Windows 8 x64 Please provide any additional information below. I've tried all sorts of ways to escape something in order to get the output of "\b" and nothing I've tried works.

Original issue: http://code.google.com/p/dngrep/issues/detail?id=194

@doug24
Copy link
Contributor

doug24 commented Jul 27, 2017

This problem is a result of a change made in 2011 to fix problem report 100 in the old google code issues. The original problem report was the user could not insert a newline in the replacement text, it would always insert the string literal "\n". Now we have the opposite problem: the user wants to insert the string literal, but the code is converting it to an escape sequence. You could argue that no one would want to insert a backspace character, but that still leaves the new line, carriage return, and tab escape sequences.

I'm thinking that the best fix would be to treat the escape sequences as string literals: for example, the string C:\test\new\bin would be inserted as shown, without inserting a tab, newline, and backspace. Then, if the user wanted a tab, newline or other escape sequence, they would use a double backslash: \t \n \r, etc. (then, of course, this would mean you cannot insert a string literal of '\n').

We would add this to the tooltip on the "Replace with" field on the UI to help with the syntax.

Any comments on this?

@JVimes
Copy link
Contributor Author

JVimes commented Aug 1, 2017

I vote for literal strings. Regex mode already handles tab, newline, etc. If there's a big demand for non-regex special chars, we can cross that bridge when we get to it.

@JVimes
Copy link
Contributor Author

JVimes commented Aug 1, 2017

Oh, are we talking about regex mode? Maybe I read this too quickly.

@doug24
Copy link
Contributor

doug24 commented Aug 1, 2017

The problem is in the replace, not in the search, and it affect both Regex and Text searches. To see the problem,

  1. create a test file with any text, for example just "text text".
  2. search for 'text' using either a regular expression or plain text.
  3. replace with the string 'C:\test\new\bin'
    and you end up with a tab, a line feed, and a backspace in your file.
    Currently, I do not think there is any way to work around this behavior using a regex or otherwise.

@JVimes
Copy link
Contributor Author

JVimes commented Aug 2, 2017

Right, current plain-text replace behavior is wrong. I think it should not support escape characters. That's what regex is for.

Plain-text replace does already support newline (via multiline mode) and tab (have to paste it in, room for improvement).

Regex escape sequences mean you have to double the slashes in the example. That's good and correct. It's regex.

We could add a third option for "plain text but with escape chars", like Notepad++ does.

@JVimes
Copy link
Contributor Author

JVimes commented Aug 2, 2017

Also, I wrote that without trying it out (at work) 😉 If doubling the slashes doesn't work for regex, then I think it's a bug.

doug24 added a commit to doug24/dnGrep that referenced this issue Aug 5, 2017
…extra backslash to insert special characters
doug24 added a commit to doug24/dnGrep that referenced this issue Aug 5, 2017
@doug24 doug24 mentioned this issue Feb 24, 2018
@doug24 doug24 closed this as completed Jun 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants