[jget] fix the jget function

This commit is contained in:
Timothy Stack 2015-11-30 21:07:18 -08:00
parent b6e10f4ee4
commit f3ca72f42d
3 changed files with 30 additions and 13 deletions

View File

@ -125,7 +125,6 @@ public:
enum match_state_t {
MS_DONE,
MS_VALUE,
MS_ELEMENT,
MS_ERR_INVALID_TYPE,
MS_ERR_NO_SLASH,
MS_ERR_INVALID_ESCAPE,
@ -188,16 +187,13 @@ public:
retval = true;
}
else if (this->jp_state == MS_VALUE) {
if (this->jp_pos[0] == '/') {
this->jp_pos += 1;
this->jp_depth += 1;
this->jp_state = MS_ELEMENT;
retval = true;
}
else {
this->jp_state = MS_ERR_NO_SLASH;
retval = false;
}
if (this->jp_pos[0] == '/') {
this->jp_pos += 1;
this->jp_depth += 1;
this->jp_state = MS_VALUE;
this->jp_array_index = -1;
}
retval = true;
}
else {
retval = true;
@ -254,7 +250,10 @@ public:
void exit_container(int32_t &depth, int32_t &index) {
depth -= 1;
if (this->jp_state == MS_VALUE && depth == this->jp_depth) {
if (this->jp_state == MS_VALUE &&
depth == this->jp_depth &&
(index == -1 || (index - 1 == this->jp_array_index)) &&
this->reached_end()) {
this->jp_state = MS_DONE;
index = -1;
}
@ -288,7 +287,7 @@ public:
else {
index = 0;
this->jp_pos += offset;
this->jp_state = MS_ELEMENT;
this->jp_state = MS_VALUE;
retval = true;
}
}

View File

@ -69,6 +69,14 @@ check_output "cannot read map" <<EOF
}
EOF
run_test ./drive_json_op get /other/val <<EOF
{ "other" : { "val" : 5 }, "val" : 3 }
EOF
check_output "cannot read nested map" <<EOF
5
EOF
run_test ./drive_json_op get "" <<EOF
[0, 1]

View File

@ -24,6 +24,16 @@ Row 0:
Column jget('[null, true, 20, 30, 40]', '/3'): 30
EOF
run_test ./drive_sql "select jget('[null, true, 20, 30, 40, {\"msg\": \"Hello\"}]', '/5/msg')"
check_error_output "" <<EOF
EOF
check_output "jget null does not work" <<EOF
Row 0:
Column jget('[null, true, 20, 30, 40, {"msg": "Hello"}]', '/5/msg'): Hello
EOF
run_test ./drive_sql "select jget('[null, true, 20, 30, 40]', '/abc')"
check_error_output "" <<EOF