@@ -542,13 +542,35 @@ func TestJSONExpressionParser(t *testing.T) {
542
542
),
543
543
NoParserHints (),
544
544
},
545
+ {
546
+ "nested object with escaped value" ,
547
+ []byte (`{"app":{"name":"great \"loki\""}` ),
548
+ []LabelExtractionExpr {
549
+ NewLabelExtractionExpr ("app" , `app` ),
550
+ },
551
+ labels .FromStrings ("foo" , "bar" ),
552
+ labels .FromStrings ("foo" , "bar" ,
553
+ "app" , `{"name":"great \"loki\""}` ,
554
+ ),
555
+ NoParserHints (),
556
+ },
557
+ {
558
+ "field with escaped value inside the json string" ,
559
+ []byte (`{"app":"{\"name\":\"great \\\"loki\\\"\"}"}` ),
560
+ []LabelExtractionExpr {
561
+ NewLabelExtractionExpr ("app" , `app` ),
562
+ },
563
+ labels .FromStrings ("foo" , "bar" ),
564
+ labels .FromStrings ("foo" , "bar" ,
565
+ "app" , `{"name":"great \"loki\""}` ,
566
+ ),
567
+ NoParserHints (),
568
+ },
545
569
}
546
570
for _ , tt := range tests {
547
- j , err := NewJSONExpressionParser (tt .expressions )
548
- if err != nil {
549
- t .Fatalf ("cannot create JSON expression parser: %s" , err .Error ())
550
- }
551
571
t .Run (tt .name , func (t * testing.T ) {
572
+ j , err := NewJSONExpressionParser (tt .expressions )
573
+ require .NoError (t , err , "cannot create JSON expression parser" )
552
574
b := NewBaseLabelsBuilderWithGrouping (nil , tt .hints , false , false ).ForLabels (tt .lbs , tt .lbs .Hash ())
553
575
b .Reset ()
554
576
_ , _ = j .Process (0 , tt .line , b )
0 commit comments