dalibo / pgtoolkit

Postgres Support from Python
https://pgtoolkit.rtfd.io/
PostgreSQL License
21 stars 9 forks source link

Prevent hba parsing error with backslash in record #93

Closed pgiraud closed 2 years ago

pgiraud commented 2 years ago

shlex.split fails with "No closing quotation"when a backslash is directly followed by a double-quote

codecov-commenter commented 2 years ago

Codecov Report

Merging #93 (bc3f5fb) into master (ce5cad7) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #93   +/-   ##
=======================================
  Coverage   98.46%   98.46%           
=======================================
  Files          10       10           
  Lines        1104     1104           
=======================================
  Hits         1087     1087           
  Misses         17       17           
Impacted Files Coverage Δ
pgtoolkit/hba.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update ce5cad7...bc3f5fb. Read the comment docs.

dlax commented 2 years ago

I think this problem reveals that the parsing method, relying on shlex.split(), might not be the best. So I wonder if it'd be worth finding an alternative implementation rather than working around. Perhaps simply splitting on blanks (with special care for blanks within double-quotes) would work?

pgiraud commented 2 years ago

@dlax I agree with you. However I doesn't seem to be that easy. I'll see what I can do.

pgiraud commented 2 years ago

@dlax That was a good idea to give it a try.

I even took into account some weird (yet possible) double-quoting values (see https://www.postgresql.org/docs/11/auth-radius.html):

host ... radius radiusservers="server1,server2" radiussecrets="""secret one"",""secret two"""
pgiraud commented 2 years ago

I took your comments into account. The commit from #95 is also included. The behavior should not be changed.