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
1=== modified file 'src/runtime/csv/csv_impl.cpp'
2--- src/runtime/csv/csv_impl.cpp 2014-02-28 01:46:12 +0000
3+++ src/runtime/csv/csv_impl.cpp 2014-03-01 01:57:20 +0000
4@@ -162,8 +162,31 @@
5 istringstream iss;
6 iss.ios::rdbuf( &buf );
7 json::lexer lex( iss );
8- return lex.next( ptoken, false ) ?
9- json::map_type( ptoken->get_type() ) : json::none;
10+ if ( !lex.next( ptoken, false ) )
11+ return json::none;
12+ json::token::type const tt = ptoken->get_type();
13+ if ( tt == json::token::number ) {
14+ //
15+ // The JSON lexer will stop lex'ing as soon as it finds a valid token. For
16+ // strings that start with numbers, e.g., "870 Market St", the lexer will
17+ // return "870" as a number token but we need to know the type of the whole
18+ // string 's'; hence we need to do an extra check for number tokens.
19+ //
20+ // If the length(t) < length(s), remove trailing whitespace from 's' and
21+ // check again. If length(t) < length(s2), it means that that the token is
22+ // really a string; if length(t) == length(s2), then the length difference
23+ // was caused only by whitespace that can be ignored and the token is still
24+ // a number.
25+ //
26+ json::token::value_type const &value = ptoken->get_value();
27+ if ( value.size() < s.size() ) {
28+ zstring s2;
29+ ascii::trim_end_space( s, &s2 );
30+ if ( value.size() < s2.size() )
31+ return json::string;
32+ }
33+ }
34+ return json::map_type( tt );
35 }
36
37 static void set_keys( store::Item_t const &item, vector<store::Item_t> *keys,
38
39=== added file 'test/rbkt/ExpQueryResults/zorba/csv/csv-parse-address.xml.res'
40--- test/rbkt/ExpQueryResults/zorba/csv/csv-parse-address.xml.res 1970-01-01 00:00:00 +0000
41+++ test/rbkt/ExpQueryResults/zorba/csv/csv-parse-address.xml.res 2014-03-01 01:57:20 +0000
42@@ -0,0 +1,3 @@
43+{
44+ "Street" : "870 Market Street"
45+}
46
47=== added file 'test/rbkt/Queries/zorba/csv/csv-parse-address.jq'
48--- test/rbkt/Queries/zorba/csv/csv-parse-address.jq 1970-01-01 00:00:00 +0000
49+++ test/rbkt/Queries/zorba/csv/csv-parse-address.jq 2014-03-01 01:57:20 +0000
50@@ -0,0 +1,7 @@
51+import module namespace csv = "http://zorba.io/modules/json-csv";
52+
53+let $csv := "870 Market Street"
54+let $options := { "field-names" : [ "Street" ] }
55+return csv:parse( $csv, $options )
56+
57+(: vim:set syntax=xquery et sw=2 ts=2 :)
58
59=== added file 'test/rbkt/Queries/zorba/csv/csv-parse-address.spec'
60--- test/rbkt/Queries/zorba/csv/csv-parse-address.spec 1970-01-01 00:00:00 +0000
61+++ test/rbkt/Queries/zorba/csv/csv-parse-address.spec 2014-03-01 01:57:20 +0000
62@@ -0,0 +1,1 @@
63+Serialization: indent=yes

Subscribers

People subscribed via source and target branches