@@ -193,8 +193,9 @@ fn parse_sd(structured_data_raw: &str) -> ParseResult<(StructuredData, &str)> {
193193 let mut rest = structured_data_raw;
194194 while !rest. is_empty ( ) {
195195 let ( sd_id, params) = take_item ! ( parse_sde( rest) , rest) ;
196+ let sub_map = sd. entry ( sd_id. clone ( ) ) ;
196197 for ( sd_param_id, sd_param_value) in params {
197- sd . insert_tuple ( sd_id . clone ( ) , sd_param_id, sd_param_value) ;
198+ sub_map . insert ( sd_param_id, sd_param_value) ;
198199 }
199200 if rest. starts_with ( ' ' ) {
200201 break ;
@@ -480,6 +481,29 @@ mod tests {
480481 assert_eq ! ( v, "29" ) ;
481482 }
482483
484+ #[ test]
485+ fn test_sd_empty ( ) {
486+ let msg = parse_message (
487+ "<78>1 2016-01-15T00:04:01Z host1 CROND 10391 - [meta@1234] some_message" ,
488+ )
489+ . expect ( "Should parse message with empty structured data" ) ;
490+ assert_eq ! ( msg. facility, SyslogFacility :: LOG_CRON ) ;
491+ assert_eq ! ( msg. severity, SyslogSeverity :: SEV_INFO ) ;
492+ assert_eq ! ( msg. hostname, Some ( String :: from( "host1" ) ) ) ;
493+ assert_eq ! ( msg. appname, Some ( String :: from( "CROND" ) ) ) ;
494+ assert_eq ! ( msg. procid, Some ( message:: ProcId :: PID ( 10391 ) ) ) ;
495+ assert_eq ! ( msg. msg, String :: from( "some_message" ) ) ;
496+ assert_eq ! ( msg. timestamp, Some ( 1452816241 ) ) ;
497+ assert_eq ! ( msg. sd. len( ) , 1 ) ;
498+ assert_eq ! (
499+ msg. sd
500+ . find_sdid( "meta@1234" )
501+ . expect( "should contain meta" )
502+ . len( ) ,
503+ 0
504+ ) ;
505+ }
506+
483507 #[ test]
484508 fn test_sd_features ( ) {
485509 let msg = parse_message ( "<78>1 2016-01-15T00:04:01Z host1 CROND 10391 - [meta sequenceId=\" 29\" sequenceBlah=\" foo\" ][my key=\" value\" ][meta bar=\" baz=\" ] some_message" ) . expect ( "Should parse complex message" ) ;
0 commit comments