[#244] Allows spaces and comments in configuration parameters #247
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit refactors the
extract_key_value()
function to handlequoted strings as values. A quoted string must start with either '"'
or '''. Everything between the quotes is handled as a value.
If quotes do not match (e.g., "foo') the value is not set, so the line
is ignored at all.
Quoted strings can contain also spaces and comment charaters.
Therefore, the following is a good string:
log_line_prefix = "PGAGROAL #%Y-%m-%d-%H:%M:%S"
Also, quotes can be nested:
log_line_prefix = "'PGAGROAL' #%Y-%m-%d-%H:%M:%S"
Values that do not need a quoting (because of spaces or comment signs)
can be quoted as well, and that will not affect the value parsing. The
following two lines are the same:
log_rotation_size = 1M
log_rotation_size = "1M"
The
extract_key_value()
function now returns also an integer toindicate if it has parsed the key and the value correctly. The return
value is not used because there is already a check on the validity of
both key and value in
pgagroal_read_configuration()
, but to becoherent the function returns a status.
This commit also allows to use comment-only line that begin with
spaces or tabs, therefore the following are all ignored lines. The
is_comment_line()
function has therefore been refactored so that thefollowing is a valid snippet of configuration:
; comment
; comment
; comment
Last, a comment can be placed on the right side of a configuration
option, so
log_line_prefix = "PGAGROAL #%Y-%m-%d-%H:%M:%S" # the prefix
is a valid line. The trick here is that any space after the option
makes the rest of the line ignored. But now, even without spaces the
comment is ignored:
log_type = create; overwrites the file
Updated also the documentation to reflect the changes.
Close #244