Merge lp:~paul-lucas/zorba/pjl-misc into lp:zorba

Proposed by Paul J. Lucas
Status: Merged
Approved by: Paul J. Lucas
Approved revision: 11462
Merged at revision: 11701
Proposed branch: lp:~paul-lucas/zorba/pjl-misc
Merge into: lp:zorba
Diff against target: 63 lines (+36/-2)
4 files modified
src/runtime/csv/csv_impl.cpp (+25/-2)
test/rbkt/ExpQueryResults/zorba/csv/csv-parse-address.xml.res (+3/-0)
test/rbkt/Queries/zorba/csv/csv-parse-address.jq (+7/-0)
test/rbkt/Queries/zorba/csv/csv-parse-address.spec (+1/-0)
To merge this branch: bzr merge lp:~paul-lucas/zorba/pjl-misc
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Paul J. Lucas Approve
Review via email: mp+208907@code.launchpad.net

Commit message

Discovered a bug where strings like street addresses, e.g., "870 Market Street", will cause an exception to be thrown due to the mis-guessing about what kind of JSON token a string really is. Fixed.

Description of the change

Discovered a bug where strings like street addresses, e.g., "870 Market Street", will cause an exception to be thrown due to the mis-guessing about what kind of JSON token a string really is. Fixed.

To post a comment you must log in.
lp:~paul-lucas/zorba/pjl-misc updated
11463. By Paul J. Lucas

Fixed typo in comment.

Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/208907

Progress dashboard at http://jenkins.zorba.io:8180/view/ValidationQueue

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue succeeded - proposal merged!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/runtime/csv/csv_impl.cpp'
--- src/runtime/csv/csv_impl.cpp 2014-02-28 01:46:12 +0000
+++ src/runtime/csv/csv_impl.cpp 2014-03-01 01:57:20 +0000
@@ -162,8 +162,31 @@
162 istringstream iss;162 istringstream iss;
163 iss.ios::rdbuf( &buf );163 iss.ios::rdbuf( &buf );
164 json::lexer lex( iss );164 json::lexer lex( iss );
165 return lex.next( ptoken, false ) ?165 if ( !lex.next( ptoken, false ) )
166 json::map_type( ptoken->get_type() ) : json::none;166 return json::none;
167 json::token::type const tt = ptoken->get_type();
168 if ( tt == json::token::number ) {
169 //
170 // The JSON lexer will stop lex'ing as soon as it finds a valid token. For
171 // strings that start with numbers, e.g., "870 Market St", the lexer will
172 // return "870" as a number token but we need to know the type of the whole
173 // string 's'; hence we need to do an extra check for number tokens.
174 //
175 // If the length(t) < length(s), remove trailing whitespace from 's' and
176 // check again. If length(t) < length(s2), it means that that the token is
177 // really a string; if length(t) == length(s2), then the length difference
178 // was caused only by whitespace that can be ignored and the token is still
179 // a number.
180 //
181 json::token::value_type const &value = ptoken->get_value();
182 if ( value.size() < s.size() ) {
183 zstring s2;
184 ascii::trim_end_space( s, &s2 );
185 if ( value.size() < s2.size() )
186 return json::string;
187 }
188 }
189 return json::map_type( tt );
167}190}
168191
169static void set_keys( store::Item_t const &item, vector<store::Item_t> *keys,192static void set_keys( store::Item_t const &item, vector<store::Item_t> *keys,
170193
=== added file 'test/rbkt/ExpQueryResults/zorba/csv/csv-parse-address.xml.res'
--- test/rbkt/ExpQueryResults/zorba/csv/csv-parse-address.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/csv/csv-parse-address.xml.res 2014-03-01 01:57:20 +0000
@@ -0,0 +1,3 @@
1{
2 "Street" : "870 Market Street"
3}
04
=== added file 'test/rbkt/Queries/zorba/csv/csv-parse-address.jq'
--- test/rbkt/Queries/zorba/csv/csv-parse-address.jq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/csv/csv-parse-address.jq 2014-03-01 01:57:20 +0000
@@ -0,0 +1,7 @@
1import module namespace csv = "http://zorba.io/modules/json-csv";
2
3let $csv := "870 Market Street"
4let $options := { "field-names" : [ "Street" ] }
5return csv:parse( $csv, $options )
6
7(: vim:set syntax=xquery et sw=2 ts=2 :)
08
=== added file 'test/rbkt/Queries/zorba/csv/csv-parse-address.spec'
--- test/rbkt/Queries/zorba/csv/csv-parse-address.spec 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/csv/csv-parse-address.spec 2014-03-01 01:57:20 +0000
@@ -0,0 +1,1 @@
1Serialization: indent=yes

Subscribers

People subscribed via source and target branches