darold / pgbadger

A fast PostgreSQL Log Analyzer
http://pgbadger.darold.net/
PostgreSQL License
3.49k stars 349 forks source link

error in 'sub set_output_extension' when $od has got special chars (special for regexp) #777

Closed bbourgier closed 1 year ago

bbourgier commented 1 year ago

Hi,

Test done with: pgbadger 12.1 commit cf9f511206

Here is my command line:

pgbadger --timezone +2 --incremental --pid-dir "C:\pgbadger\__test_retention_11.8.BBO.01" --retention 13 --start-monday --outdir "C:\pgbadger\__test_retention_11.8.BBO.01\report" --prefix "%m [%p]: [%l-1] user=%u,db=%d,app=%a,client=%h " --exclude-appname "psql,createdb,pg_dumpall,pg_restore" --exclude-line ".*pgAdmin 4.*" --exclude-line ".*DBeaver.*" --html-outdir "C:\pgbadger\__test_retention_11.8.BBO.01\html" --extra-files --logfile-list "C:\pgbadger\__test_retention_11.8.BBO.01\logfilelist_NEW.txt" -v

As you can see, my outdir is:

C:\pgbadger\__test_retention_11.8.BBO.01\report

Output with the ERROR is:

DEBUG: pgBadger version 12.1.
Can't find Unicode property definition "g" in regex; marked by <-- HERE in m/^C:\pg <-- HERE badger\__test_retention_11.8.BBO.01\report/ at c:\pgbadger\pgbadger-11.8.commit-cf9f511206 line 19288.

After analysis, the issue is due to the line:

sub set_output_extension
{
[...]
    # Add the destination directory
    $of = $od . '/' . $of if ($od && $of !~ m#^$od#);
[...]
}

The problem is that $od contains special chars and that they must be escaped to do string comparison through the regexp engine.

My suggestion (and my test proved to me it works) is to do automatic escaping by replacing the line:

sub set_output_extension
{
[...]
    # Add the destination directory
    $of = $od . '/' . $of if ($od && $of !~ m#^$od#);
[...]
}

by

sub set_output_extension
{
[...]
    # Add the destination directory
    $of = $od . '/' . $of if ($od && $of !~ m#^\Q$od\E#);
[...]
}

Regards.

darold commented 1 year ago

Commit c658e00 applies your patch.