@@ -620,7 +620,7 @@ class SearchContainer extends React.Component<{}, ISearchState> {
620620 headers . push ( { label : CONSTANTS . AGE_LABEL , key : 'accountId.age' } ) ;
621621 headers . push ( {
622622 label : CONSTANTS . PHONE_NUMBER_LABEL ,
623- key : 'accountId.age ' ,
623+ key : 'accountId.phoneNumber ' ,
624624 } ) ;
625625 headers . push ( { label : 'Resume' , key : 'application.general.URL.resume' } ) ;
626626 headers . push ( { label : 'Github' , key : 'application.general.URL.github' } ) ;
@@ -698,36 +698,45 @@ class SearchContainer extends React.Component<{}, ISearchState> {
698698 key : 'application.other.sendEmail' ,
699699 } ) ;
700700 }
701- const tempHeaders : string [ ] = [ ] ;
702- headers . forEach ( ( header ) => {
703- tempHeaders . push ( header . label ) ;
704- } ) ;
705- const csvData : string [ ] = [ tempHeaders . join ( ',' ) ] ;
701+ // Build header row
702+ const headerLabels = headers . map ( ( h ) => h . label ) ;
703+ const csvRows : string [ ] = [ headerLabels . join ( ',' ) ] ;
704+
705+ // Build each data row with proper escaping
706706 this . filter ( ) . forEach ( ( result ) => {
707- if ( result . selected ) {
708- const row : string [ ] = [ ] ;
709- headers . forEach ( ( header ) => {
710- let value ;
711- if ( header . key . indexOf ( '.' ) >= 0 ) {
712- const nestedAttr = header . key . split ( '.' ) ;
713- value = getNestedAttr ( result . hacker , nestedAttr ) ;
714- if ( / [ , " \n ] / . test ( value ) ) {
715- value = `"${ value . replace ( / " / g, '""' ) } "` ;
716- }
717- } else {
718- value = result . hacker [ header . key ] ;
719- if ( / [ , " \n ] / . test ( value ) ) {
720- value = `"${ value . replace ( / " / g, '""' ) } "` ;
721- }
722- }
723- row . push ( value ) ;
724- } ) ;
725- csvData . push ( row . join ( '\t' ) ) ;
726- }
707+ if ( ! result . selected ) return ;
708+ const row : string [ ] = [ ] ;
709+ headers . forEach ( ( header ) => {
710+ let value : any = '' ;
711+ if ( header . key . indexOf ( '.' ) >= 0 ) {
712+ const nestedAttr = header . key . split ( '.' ) ;
713+ value = getNestedAttr ( result . hacker , nestedAttr ) ;
714+ } else {
715+ value = ( result . hacker as any ) [ header . key ] ;
716+ }
717+
718+ // Handle null/undefined, arrays, and coerce to string
719+ if ( value == null ) {
720+ value = '' ;
721+ } else if ( Array . isArray ( value ) ) {
722+ value = value . join ( '; ' ) ;
723+ } else {
724+ value = String ( value ) ;
725+ }
726+
727+ // Escape double quotes and wrap if needed
728+ if ( / [ " , \n ] / . test ( value ) ) {
729+ value = `"${ value . replace ( / " / g, '""' ) } "` ;
730+ }
731+
732+ row . push ( value ) ;
733+ } ) ;
734+
735+ csvRows . push ( row . join ( ',' ) ) ;
727736 } ) ;
728737
729738 fileDownload (
730- csvData . join ( '\n' ) ,
739+ csvRows . join ( '\n' ) ,
731740 'hackerData.csv' ,
732741 'text/csv;charset=utf-8'
733742 ) ;
0 commit comments