@@ -522,13 +522,35 @@ func TestJSONExpressionParser(t *testing.T) {
522
522
),
523
523
NoParserHints (),
524
524
},
525
+ {
526
+ "nested object with escaped value" ,
527
+ []byte (`{"app":{"name":"great \"loki\""}` ),
528
+ []LabelExtractionExpr {
529
+ NewLabelExtractionExpr ("app" , `app` ),
530
+ },
531
+ labels .FromStrings ("foo" , "bar" ),
532
+ labels .FromStrings ("foo" , "bar" ,
533
+ "app" , `{"name":"great \"loki\""}` ,
534
+ ),
535
+ NoParserHints (),
536
+ },
537
+ {
538
+ "field with escaped value inside the json string" ,
539
+ []byte (`{"app":"{\"name\":\"great \\\"loki\\\"\"}"}` ),
540
+ []LabelExtractionExpr {
541
+ NewLabelExtractionExpr ("app" , `app` ),
542
+ },
543
+ labels .FromStrings ("foo" , "bar" ),
544
+ labels .FromStrings ("foo" , "bar" ,
545
+ "app" , `{"name":"great \"loki\""}` ,
546
+ ),
547
+ NoParserHints (),
548
+ },
525
549
}
526
550
for _ , tt := range tests {
527
- j , err := NewJSONExpressionParser (tt .expressions )
528
- if err != nil {
529
- t .Fatalf ("cannot create JSON expression parser: %s" , err .Error ())
530
- }
531
551
t .Run (tt .name , func (t * testing.T ) {
552
+ j , err := NewJSONExpressionParser (tt .expressions )
553
+ require .NoError (t , err , "cannot create JSON expression parser" )
532
554
b := NewBaseLabelsBuilderWithGrouping (nil , tt .hints , false , false ).ForLabels (tt .lbs , tt .lbs .Hash ())
533
555
b .Reset ()
534
556
_ , _ = j .Process (0 , tt .line , b )
0 commit comments