@@ -540,6 +540,44 @@ export function runTests() {
540540 assert . equal ( csv , csvTestData . nestedDotKeys . replace ( / \\ \. / g, '.' ) ) ;
541541 } ) ;
542542
543+ // Test case for #247
544+ it ( 'should not escape nested dots in keys with nested dots in them if turned off via the option' , ( ) => {
545+ const csv = json2csv ( jsonTestData . wildcardMatch , {
546+ keys : [ 'foo' , 'bar' , 'baz.a' , 'baz.array' ] ,
547+ } ) ;
548+ assert . equal ( csv , csvTestData . wildcardMatch ) ;
549+ } ) ;
550+
551+ // Test case for #247
552+ it ( 'should not escape nested dots in keys with nested dots in them if turned off via the option' , ( ) => {
553+ const csv = json2csv ( jsonTestData . wildcardMatch , {
554+ keys : [ 'foo' , 'bar' , { field : 'baz.a' , wildcardMatch : true } ] ,
555+ } ) ;
556+ assert . equal ( csv , csvTestData . wildcardMatch ) ;
557+ } ) ;
558+
559+ // Test case for #247
560+ it ( 'should not escape nested dots in keys with nested dots in them if turned off via the option' , ( ) => {
561+ const updatedCsv = csvTestData . wildcardMatch . replace ( 'baz.a,baz.array' , 'baz.a,baz.b,baz.array' )
562+ . replace ( 'a,c' , 'a,b,c' ) ;
563+
564+ const csv = json2csv ( jsonTestData . wildcardMatch , {
565+ keys : [ 'foo' , 'bar' , { field : 'baz' , wildcardMatch : true } ] ,
566+ } ) ;
567+ assert . equal ( csv , updatedCsv ) ;
568+ } ) ;
569+
570+ // Test case for #247
571+ it ( 'should not escape nested dots in keys with nested dots in them if turned off via the option' , ( ) => {
572+ const updatedCsv = csvTestData . wildcardMatch . replace ( 'foo,bar,baz.a,baz.array' , 'foo,baz.a,baz.array,bar' )
573+ . replace ( 'foo,bar,a,c' , 'foo,a,c,bar' ) ;
574+
575+ const csv = json2csv ( jsonTestData . wildcardMatch , {
576+ keys : [ 'foo' , { field : 'baz.a' , wildcardMatch : true } , 'bar' ] ,
577+ } ) ;
578+ assert . equal ( csv , updatedCsv ) ;
579+ } ) ;
580+
543581 it ( 'should use a custom value parser function when provided' , ( ) => {
544582 const updatedCsv = csvTestData . trimmedFields . split ( '\n' ) ;
545583 const textRow = 'Parsed Value,Parsed Value,Parsed Value,Parsed Value,Parsed Value' ;
0 commit comments