Hi list, I had a problem using MIFDataStore for reading MID file
containing text attribute with quote(s) inside the string (which are
also quoted in MIF format).
eg.
357,"RBE","TF","TUR","Si","TI","","TO","GPS","","",0,0,"20070321","","designated
"Emergency Presence""
When the MIFDataStore read that line, it fails returning exception:
"Error reading quoted string" on last attribute.
Added check on quote and separator in order to get all token even if a
quote is found inside a quoted string.
See patch attached for comments.
Cheers.
Francois
PS: this bug was found working on SpatialDataIntegrator
http://www.talendforge.org/bugs/view.php?id=3092
Index: src/main/java/org/geotools/data/mif/MIFStringTokenizer.java
===================================================================
--- src/main/java/org/geotools/data/mif/MIFStringTokenizer.java (revision 29329)
+++ src/main/java/org/geotools/data/mif/MIFStringTokenizer.java (working copy)
@@ -112,15 +112,20 @@
while (loop) {
while ((index < len) && (line.charAt(index) != '"'))
- index++;
-
- if ((index < (len - 1)) && (line.charAt(index + 1) == '"')) {
- index += 2;
+ index ++;
+
+ if ( (index < (len - 2)) &&
+ (line.charAt(index) == '"') &&
+ (line.charAt(index + 1) == separator)) {
+ loop = false;
+ } else if ( (index == (len - 1)) &&
+ (line.charAt(index) == '"') ) {
+ loop = false;
} else {
- loop = false;
+ index ++;
}
}
-
+
token = line.substring(1, index).replaceAll("\"\"", "\"");
line = ltrim(line.substring(index + 1));
Index: src/test/java/org/geotools/data/mif/MIFStringTokenizerTest.java
===================================================================
--- src/test/java/org/geotools/data/mif/MIFStringTokenizerTest.java (revision 29329)
+++ src/test/java/org/geotools/data/mif/MIFStringTokenizerTest.java (working copy)
@@ -101,6 +101,35 @@
}
}
+
+ /*
+ * Class under test for String getToken(char, boolean, boolean)
+ */
+ public void testGetTokencharbooleanbooleanInQuote() {
+ tok.readLine("\"foo \"quote inside quoted string\" bar\",next");
+
+ try {
+ assertEquals("foo \"quote inside quoted string\" bar", tok.getToken(',', false, true));
+ } catch (ParseException e) {
+ fail(e.getMessage());
+ }
+ }
+
+
+ /*
+ * Class under test for String getToken(char, boolean, boolean)
+ */
+ public void testGetTokencharbooleanbooleanInQuoteEnd() {
+ tok.readLine("\"foo \"quote inside quoted string\"\"");
+
+ try {
+ assertEquals("foo \"quote inside quoted string\"", tok.getToken(',', false, true));
+ } catch (ParseException e) {
+ fail(e.getMessage());
+ }
+ }
+
+
/*
* Class under test for String getToken(char)
*/
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users