@@ -531,7 +531,7 @@ static byte[] decode(String hex) {
531
531
/**
532
532
* A regex pattern of a line in a CSV file.
533
533
*/
534
- private static final Pattern CSV_LINE_PATTERN = Pattern .compile ("(?<=^|,)\\ s*([^\" ,]*|\" ([^\" ]|\" \" )*\" )\\ s*(,|$)" );
534
+ private static final Pattern CSV_LINE_PATTERN = Pattern .compile ("(?<=^|,)\\ s*([^\" ,]*|\" ([^\" ]|\" \" )*\" )\\ s*(,|$)" );
535
535
536
536
/**
537
537
* Splits the given CSV line into its values.
@@ -543,12 +543,29 @@ static byte[] decode(String hex) {
543
543
*/
544
544
@ Nullable
545
545
static String [] splitCSV (String line ) {
546
- Matcher matcher = CSV_LINE_PATTERN . matcher ( line );
546
+
547
547
548
548
int lastEnd = 0 ;
549
549
ArrayList <String > result = new ArrayList <>();
550
550
551
- while (matcher .find ()) {
551
+ // avoid regex matching quoted var names
552
+ if (line .startsWith ("\" " )) {
553
+ // find closing quote '",'
554
+ int start = 0 ;
555
+ while (start < line .length () && (start == 0 || line .charAt (start - 1 ) == '"' )) {
556
+ start = line .indexOf ("\" ," , start + 2 );
557
+ if (start == -1 ) {
558
+ // No closing quote found
559
+ return null ;
560
+ }
561
+ }
562
+ result .add (line .substring (1 , start ).replace ("\" \" " , "\" " ));
563
+ lastEnd = start + 2 ;
564
+ }
565
+
566
+ Matcher matcher = CSV_LINE_PATTERN .matcher (line );
567
+
568
+ while (matcher .find (lastEnd )) {
552
569
if (lastEnd != matcher .start ())
553
570
return null ; // other stuff inbetween finds
554
571
0 commit comments