Keep an escaped value that equals the null string#626
Conversation
garydgregory
left a comment
There was a problem hiding this comment.
Hello @saleemno1
Please see my comment.
| @Test | ||
| void testEscapedNullStringIsAValue() throws Exception { | ||
| // "\N" is the MySQL and PostgreSQL null marker, "\\N" is the value "\N", which is what the printer writes for it. | ||
| for (final CSVFormat format : new CSVFormat[] { CSVFormat.MYSQL, CSVFormat.POSTGRESQL_TEXT, CSVFormat.ORACLE }) { |
There was a problem hiding this comment.
Use a JUnit @ParameterizedTest instead of a loop.
There was a problem hiding this comment.
Done, it's an @ParameterizedTest with @EnumSource now. I also folded PostgreSQLCsv into the list since it has the same \N null string and was missing from the loop.
garydgregory
left a comment
There was a problem hiding this comment.
Hello @saleemno1
Thank you for your update. Please see my comment.
| final CSVFormat format = predefined.getFormat(); | ||
| final StringWriter writer = new StringWriter(); | ||
| try (CSVPrinter printer = new CSVPrinter(writer, format)) { | ||
| printer.printRecord("\\N", null); |
There was a problem hiding this comment.
Refactor the magic string \\N into a constant or a local variable with a name that explains its intent. Since there are 2 such instances in this method, it will also make it obvious that both magic strings are indeed intended to be the same.
CSVParser.handleNullcompares the fully unescaped token against the format's null string, so a value that really is\Nand that the printer correctly wrote as\\NforMYSQL,POSTGRESQL_TEXT,POSTGRESQL_CSVandORACLEcomes back asnull; the lexer now records whether an escape sequence was actually translated, and only an untranslated token can be the null marker.mvn; that'smvnon the command line by itself.