= Escape characters now honored

This commit is contained in:
Matthew Cech
2019-07-03 00:14:46 -07:00
parent 76e00a42dc
commit 15f3ca059f
4 changed files with 15 additions and 22 deletions
+5 -3
View File
@@ -14,8 +14,10 @@ import java.util.Vector;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import com.opencsv.CSVWriter;
import com.opencsv.RFC4180ParserBuilder;
import utils.GlobalLog;
import utils.StringUtils;
public class ConfigCSV
{
@@ -41,7 +43,7 @@ public class ConfigCSV
return new CSVWriter(writer,
CSVWriter.DEFAULT_SEPARATOR,
CSVWriter.DEFAULT_QUOTE_CHARACTER,
'\\',
CSVWriter.DEFAULT_ESCAPE_CHARACTER,
CSVWriter.DEFAULT_LINE_END);
}
@@ -60,7 +62,7 @@ public class ConfigCSV
}
Reader reader = Files.newBufferedReader(Paths.get(filepath));
CSVReader csvReader = new CSVReaderBuilder(reader).withSkipLines(1).build();
CSVReader csvReader = new CSVReaderBuilder(reader).withSkipLines(1).withCSVParser(new RFC4180ParserBuilder().build()).build();
fileContents.clear();
// Read contents. As for the line number, we not only start counting at 1, we also skip the header.
@@ -74,7 +76,7 @@ public class ConfigCSV
continue;
}
ConfigItem parsedLine = new ConfigItem(record[0], record[1], record[2]);
ConfigItem parsedLine = new ConfigItem(StringUtils.unEscape(record[0]), StringUtils.unEscape(record[1]), StringUtils.unEscape(record[2]));
fileContents.add(parsedLine);
++line;
}
+3 -1
View File
@@ -1,5 +1,7 @@
package core;
import utils.StringUtils;
// Everything in here must be a string type. This class does not
// perform any parsing past naming columns, and just holds the raw data.
public class ConfigItem
@@ -30,7 +32,7 @@ public class ConfigItem
public String[] getAll()
{
return new String[] {type, key, value};
return new String[] {StringUtils.reEscape(type), StringUtils.reEscape(key), StringUtils.reEscape(value) };
}
public String toString()