TextPad hangs when using this regex

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
666shooter
Posts: 2
Joined: Thu Aug 07, 2008 6:13 pm

TextPad hangs when using this regex

Post by 666shooter »

Hi there,

I think I stumbled upon a small bug in TextPad, here's how to reproduce it:

-Open a new empty document
-Type an '*' in the document
-Open the replace dialog
-search for '*' and replace with nothing
-press 'Replace all'

result: TextPad hangs

Its no biggie, since this particular regex won't occur that often, I typed it by accident. But still, it killed TextPad :)

Cheers,

Roland

P.S. I'm using the latest version: 5.2.0
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

The "*" is a reserved character.

Ir you remove the checkmark from Regular Expression, then the Search/Replace works fine.

If you have Regular Expression with a checkmark, then, tTo replace "*" you need to preface it with a backslash
Search for \*, replace with nothing wotks fine now.

Without the backslash, you are using the "*" illegaly, that is why it is hanging. The "*" must be prefaced with some other character. It is looking for an umlimited number of the preceeding character. I fon't think this is a bug, but it is an illegal use of that character.
Hope this was helpful.............good luck,
Bob
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

In my opinion, it _is_ a bug.
Textpad should report the syntax error in the "regex" to the user (similar to the way unbalanced parentheses/brackets/braces are reported) and should not start trying to search for it ...
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Good point MudGuard, I hope this does not become a never ending debate. In my opinion, it is not a bug. As you noted, your opinion is different from my opinion. Facts will be hard to determine on this one.

It is impractical to come up with error trapping for every type of instance that an operator does not follow instructions. It can be done for syntax errors.

I think this is just not putting in a valid character with the parameter, it is not a syntax error like mismatched brackets.

I get the same result if I try Search/Replace for 9{1} with 8.
That works OK, but if I leave out the "9", I get the same type of error, just loops looking for 1 instance of nothing.

In any case, there is a work around:
When you are supposed to put in a character to search for, then put in a character to search for.
Hope this was helpful.............good luck,
Bob
666shooter
Posts: 2
Joined: Thu Aug 07, 2008 6:13 pm

Post by 666shooter »

I agree that I was doing something illegal, like I said, I typed it by accident. But you have to admit its rather frustrating that a typo leads to me having to kill the instance of textpad.
I wasn't working on anything important in particular, had that been different I think I would have been rather frustrated for losing my work...

But I agree its a tough one for textpad to catch, still, if it is at all possible than it would be very nice if it could be resolved.
User avatar
helios
Posts: 711
Joined: Sun Mar 02, 2003 5:52 pm
Location: Helios Software Solutions
Contact:

Post by helios »

The TextPad Help files section on Replacement Expressions states the following:

Warning:
Beware of replacing a pattern that is matched with a regular expression that can optionally match nothing, such as ".?" or a "*". In these degenerate cases, TextPad can go into a loop, until the line becomes too long.
Helios Software Solutions
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

helios wrote:Beware of replacing a pattern that is matched with a regular expression that can optionally match nothing, such as ".?" or a "*". In these degenerate cases, TextPad can go into a loop, until the line becomes too long.
This does not apply here.

A quantifier (*, ?, +, {x,y}) can't stand on its own, it needs a piece to work on. A regex consisting of only a quantifier or a regex starting with a quantifier should lead to a syntax error message (like the unmatched {}).

The warning would apply to .* which is a valid regex while * on its own is not a valid regex.
tmitchell
Posts: 1
Joined: Tue Aug 12, 2008 8:51 pm

TextPad hangs when using this regex

Post by tmitchell »

I also encountered this bug and agree that it should be fixed ASAP. Since it hangs TextPad you have to kill the app and lose any unsaved changes.

Invalid regular expressions should not hang the application. That's like saying that it is okay for the application to hang if the user requests to print page 2 of a one page document.

Another example I encountered this with was doing a Replace All on " +|" (minus the quotes). Again it was a typo. I'd forgotten to escape the | character, but that doesn't change the fact that TextPad couldn't handle it. Because my replacement expression was less text than the search expression, the line would never grow "too long" as referenced by the help. Handling this is not that difficult and it is handled by numerous other applications out there.

Helios: The warning in the help file is great as a workaround, but that doesn't change the fact that not handling an infinite loop condition is a bug.

Other than this issue (and the fact you can't middle click to close a tab) I'm delighted with TextPad.
Post Reply