Closed funzoneq closed 9 years ago
@funzoneq Thanks for reporting this.
I found the error, it is because the \n
is not escaped on your regular expression.
I'm not sure if this is an error or not. So give me a little of time for this.
FYI there is a channel on freenode #toml-rb
where you can find me
If you read it from a file it works. So probably it is an issue or is weird behavior on ruby's strings.
Could you tell me your expected hash ? (Only the regular expression needed)
heka = { "syslog_transform_decoder" => { "match_regex" => '^<(?P<Pri>\d+)>(?P<Timestamp>\w{3}\s+\d+\s+\d+:\d+:\d+) (?P<Hostname>[^\s]+) (?P<Process>[\w\/]+)\[(?P<Pid>\d+)\]:\s+(?P<Message>[^\n]+)' }}
would output:
{
"syslog_transform_decoder"=> {
"match_regex"=>"^<(?P<Pri>\\d+)>(?P<Timestamp>\\w{3}\\s+\\d+\\s+\\d+:\\d+:\\d+) (?P<Hostname>[^\\s]+) (?P<Process>[\\w\\/]+)\\[(?P<Pid>\\d+)\\]:\\s+(?P<Message>[^\\n]+)"
}
}
@funzoneq The issue is you were using <<-EOF.
Look at this example
irb> a = %q(match_regex = '^<(?P<Pri>\d+)>(?P<Timestamp>\w{3}\s+\d+\s+\d+:\d+:\d+) (?P<Hostname>[^\s]+) (?P<Process>[\w\/]+)\[(?P<Pid>\d+)\]:\s+(?P<Message>[^\n]+)')
=> "match_regex = '^<(?P<Pri>\\d+)>(?P<Timestamp>\\w{3}\\s+\\d+\\s+\\d+:\\d+:\\d+) (?P<Hostname>[^\\s]+) (?P<Process>[\\w\\/]+)\\[(?P<Pid>\\d+)\\]:\\s+(?P<Message>[^\\n]+)'"
irb> TOML.parse a
=> {"match_regex"=>
"^<(?P<Pri>\\d+)>(?P<Timestamp>\\w{3}\\s+\\d+\\s+\\d+:\\d+:\\d+) (?P<Hostname>[^\\s]+) (?P<Process>[\\w\\/]+)\\[(?P<Pid>\\d+)\\]:\\s+(?P<Message>[^\\n]+)"}
Ok, weird. Thanks for the clarification.
Gives the following error: