From 70dc72e47750d5005f3767848770c17d2e1a57bc Mon Sep 17 00:00:00 2001 From: Alex Knox Date: Thu, 18 Jul 2024 11:53:01 -0500 Subject: [PATCH] allow escape sequences --- .../evolveum/polygon/connector/csv/util/Util.java | 13 +++++++++++++ .../polygon/connector/csv/ConfigurationTest.java | 12 ++++++++++++ src/test/resources/create-tabs.tsv | 2 ++ 3 files changed, 27 insertions(+) create mode 100644 src/test/resources/create-tabs.tsv diff --git a/src/main/java/com/evolveum/polygon/connector/csv/util/Util.java b/src/main/java/com/evolveum/polygon/connector/csv/util/Util.java index d157226..c11767b 100644 --- a/src/main/java/com/evolveum/polygon/connector/csv/util/Util.java +++ b/src/main/java/com/evolveum/polygon/connector/csv/util/Util.java @@ -226,6 +226,19 @@ public static Character toCharacter(String value) { return null; } + if (value.length() == 2 && value.startsWith("\\")) { + // This is likely to be an escape sequence, like \t + // We'll take advantage of Properties to convert this to a character + Properties props = new Properties(); + try { + props.load(new StringReader("key=" + value)); + } catch (IOException ex) { + throw new ConfigurationException("Can't cast to character, reason: " + ex.getMessage(), ex); + } + + value = props.getProperty("key"); + } + if (value.length() != 1) { throw new ConfigurationException("Can't cast to character, illegal string size: " + value.length() + ", should be 1"); diff --git a/src/test/java/com/evolveum/polygon/connector/csv/ConfigurationTest.java b/src/test/java/com/evolveum/polygon/connector/csv/ConfigurationTest.java index 464ec94..e007e8e 100644 --- a/src/test/java/com/evolveum/polygon/connector/csv/ConfigurationTest.java +++ b/src/test/java/com/evolveum/polygon/connector/csv/ConfigurationTest.java @@ -49,4 +49,16 @@ public void testMissingMultivalueDelimiter() throws Exception { ConnectorFacade connector = setupConnector("/create.csv", config); connector.test(); } + + @Test + public void testTabDelimiter() throws Exception { + CsvConfiguration config = new CsvConfiguration(); + config.setUniqueAttribute("uid"); + config.setFieldDelimiter("\\t"); + config.setReadOnly(true); + + ConnectorFacade connector = setupConnector("/create-tabs.tsv", config); + connector.test(); + + } } diff --git a/src/test/resources/create-tabs.tsv b/src/test/resources/create-tabs.tsv new file mode 100644 index 0000000..f7e4738 --- /dev/null +++ b/src/test/resources/create-tabs.tsv @@ -0,0 +1,2 @@ +firstName uid lastName password +john 123 doe qwe123 \ No newline at end of file