fix: preserve hash character in pg_service.conf passwords#3
Conversation
The # character was being treated as a comment delimiter by ConfigObj, truncating passwords like abc#123 to abc. Added comment_tokens=[] to disable this behavior. Fixes dbcli#1575
There was a problem hiding this comment.
Pull request overview
Adjusts parsing of ~/.pg_service.conf so passwords containing # are not truncated during service lookup (Fixes dbcli#1575).
Changes:
- Updates
parse_service_info()to constructConfigObjwithcomment_tokens=[]to prevent#from being treated as a comment delimiter.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| skipped_lines = skip_initial_comment(f) | ||
| try: | ||
| service_file_config = ConfigObj(f) | ||
| service_file_config = ConfigObj(f, comment_tokens=[]) |
There was a problem hiding this comment.
Setting comment_tokens=[] disables all comment parsing, so standard pg_service.conf files containing comment lines beginning with '#' (not just at the top) will be treated as invalid entries and may raise ParseError. This is a functional regression versus the previous behavior where '#' comment lines were accepted; consider keeping full-line comment handling while only disabling inline comment stripping (e.g., switch to configparser with inline_comment_prefixes disabled, or configure ConfigObj to not strip inline comments but still ignore full-line comments).
| skipped_lines = skip_initial_comment(f) | ||
| try: | ||
| service_file_config = ConfigObj(f) | ||
| service_file_config = ConfigObj(f, comment_tokens=[]) |
There was a problem hiding this comment.
This change alters parsing semantics for pg_service.conf; please add/adjust tests to cover passwords containing '#' and also ensure that comment lines (e.g., lines starting with '#') within/between sections still parse correctly after the change.
Fixes dbcli#1575
The
#character is treated as a comment delimiter by ConfigObj, which truncates passwords likeabc#123toabc.This fix adds
comment_tokens=[]to theConfigObj()call inparse_service_info()to disable comment parsing, allowing#characters within password values.Before
After