Re: Tighten up a few overly lax regexes in pg_dump's tap tests

From: "Tels" <nospam-pg-abuse(at)bloodgate(dot)com>
To: "Michael Paquier" <michael(at)paquier(dot)xyz>
Cc: "Daniel Gustafsson" <daniel(at)yesql(dot)se>, "David Rowley" <david(dot)rowley(at)2ndquadrant(dot)com>, "PostgreSQL Hackers" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Tighten up a few overly lax regexes in pg_dump's tap tests
Date: 2019-02-07 12:55:32
Message-ID: 9d73773e4a10cc209b6fd25cda5e06c4.squirrel@sm.webmail.pair.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Moin,

On Wed, February 6, 2019 8:10 pm, Michael Paquier wrote:
> On Wed, Feb 06, 2019 at 03:41:20PM +0100, Daniel Gustafsson wrote:
>> Correct. One could argue that the regex is still suboptimal since
>> “COMMENT ON
>> DATABASE postgres IS ;” will be matched as well, but there I think the
>> tradeoff
>> for readability wins.
>
> Okay, that looks like an improvement anyway, so committed after going
> over the tests for similar problems, and there was one for CREATE
> DATABASE and DROP ROLE. It is possible to have a regex which tells as
> at least one non-whitespace character, but from what I can see these
> don't really improve the readability.

Sorry for being late to the party, but it just occured to me that while
".+" is definitely an improvement over ".*", it isn't foolproof either,
as it also matches ";".

Thus:

regexp => qr/^COMMENT ON DATABASE postgres IS .+;/m,

matches things like:

'COMMENT ON DATABASE postgres IS ;;'
'COMMENT ON DATABASE postgres IS ;'
'COMMENT ON DATABASE postgres IS --;'

etc.

I'm not sure it is really necessary to deal with these cases, but one
possibility would be to pre-compute regexps:

$QR_COMMENT = qr/[^ ;]+/;
$QR_IDENTIFIER = qr/[^ ;]+/; # etc

or whataver is the thing that should actually be matched here and use them
like so:

regexp => qr/^COMMENT ON DATABASE postgres IS $QR_COMMENT;/m,

That way it is easily changable and quite readable.

Oh, one more question. Shouldn't these regexps that start with "^" also
end with "$"? Or can there be output like:

'COMMENT ON DATABASE postgres IS $QR_IDENTIFIER; SELECT 1;'

?

Best regards,

Tels

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message REIX, Tony 2019-02-07 14:18:04 RE: Shared Memory: How to use SYSV rather than MMAP ?
Previous Message Etsuro Fujita 2019-02-07 12:55:18 Re: Problem while updating a foreign table pointing to a partitioned table on foreign server