diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-11-28 11:19:51 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-11-28 11:19:51 -0500 |
commit | 2e23773bf9aecd2665b369e55e2589c2db13e1f8 (patch) | |
tree | 41239cd0d58bae5030dbed3c4055138381a661c4 /tools | |
parent | b609747023b077b98452ca06f14573d1cdbdab41 (diff) | |
download | mongo-2e23773bf9aecd2665b369e55e2589c2db13e1f8.tar.gz |
fix csv parsing with escaped fields SERVER-441
Diffstat (limited to 'tools')
-rw-r--r-- | tools/import.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/tools/import.cpp b/tools/import.cpp index 3b4bfd6adeb..85005ab848f 100644 --- a/tools/import.cpp +++ b/tools/import.cpp @@ -74,15 +74,25 @@ class Import : public Tool { name = ss.str(); } pos++; - - char * end = strstr( line , _sep ); + + int skip = 1; + char * end; + if ( _type == CSV && line[0] == '"' ){ + line++; + end = strstr( line , "\"" ); + skip = 2; + } + else { + end = strstr( line , _sep ); + } + if ( ! end ){ _append( b , name , string( line ) ); break; } _append( b , name , string( line , end - line ) ); - line = end + 1; + line = end + skip; } return b.obj(); |