create new tag
, view all tags

Bug: GNU egrep Breaks with Escaped Curly Brace

GNU egrep (as of version 2.4.2) breaks on \{\} which is used in METASEARCH. My version gives the log entry

"egrep: Invalid content of \{\}"

in Apache's error log.

The GNU grep manpage says the following about this:

      Traditional egrep did not support the { metacharacter, and some egrep implementations support \{ instead,  so  portable  scripts
       should avoid { in egrep patterns and should use [{] to match a literal {.

The following should fix that bug:

--- TWiki.pm.old        Sat Feb  1 18:55:21 2003

+++ TWiki.pm    Thu May  1 22:45:51 2003
@@ -1435,10 +1435,10 @@
     my $searchWeb = "all";

     if( $attrType eq "topicmoved" ) {
-       $searchVal = "%META:TOPICMOVED\{.*from=\\\"$attrWeb\.$attrTopic\\\".*\}%";
+       $searchVal = "%META:TOPICMOVED[{].*from=\\\"$attrWeb\.$attrTopic\\\".*[}]%";
     } elsif ( $attrType eq "parent" ) {
        $searchWeb = $attrWeb;
-       $searchVal = "%META:TOPICPARENT\{.*name=\\\"($attrWeb\\.)?$attrTopic\\\".*\}%";
+       $searchVal = "%META:TOPICPARENT[{].*name=\\\"($attrWeb\\.)?$attrTopic\\\".*[}]%";

     my $text = &TWiki::Search::searchWeb( "1", $searchWeb, $searchVal, "",

And works on my Debian Linux 3.0r1 stable (Woody).

Test case

Attempt to perform a METASEARCH, such as the following:

%METASEARCH{type="parent" web="Codev" topic="GNUEgrepBreaksWithEscapedCurlyBrace" title="Related: "}%


TWiki version: 01 Feb 2003
TWiki plugins: SlideShowPlugin, BugzillaLinkPlugin
Server OS: Debian Linux 3.0r1 stable (Woody)
Web server: Apache 1.3.26
Perl version: 5.6.1
Client OS: Debian Linux unstable (Sid)
Web Browser: Konqueror (as of KDE 3.1.1)

-- AlanShields - 02 May 2003

Follow up

Fix record

Now fixed in TWikiAlphaRelease - thanks for the patch!

-- RichardDonkin - 02 May 2003

Category: TWikiPatches

I get a crash when I run TWiki on a DEC Unix system which does not have GNU egrep, but rather a DEC implementation. The error is similar to the one that your patch is intended to fix. But I fixed it by adding more back slash around squiggly brackets in the grep command line.

Here is my patch to Search.pm

<                 $tempVal = `$acmd`;
>                #PJ Fix 2003-06-18
>                $acmd =~ s/(\{)/\\\{/ ;
>                $acmd =~ s/(\})/\\}/ ;
>                $tempVal = `$acmd`;

That works, but I found it by trial and error. Their man page calls for back slashes to protect squiggly braces.

I will try your fix above to see if it works too. But I was curious to ask if you know if these two things are related issues.

-- PaulJohnson

Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2004-02-07 - PeterThoeny
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.