project-open-data / csv-to-api

Proof of concept to dynamically generate RESTful APIs from static CSVs
http://labs.data.gov/csv-to-api/
326 stars 81 forks source link

Multi-word column names aren't supported by filter #16

Open waldoj opened 11 years ago

waldoj commented 11 years ago

Filtering by single-word column names (e.g., chamber, size, state) works fine, but filtering by multi-word column names (e.g., region code, Building State) does not, even with those column names are URL encoded (e.g., region+code or region%20code). Add in support for URL-encoded multi-word column names, and document the need to URL encode them (as opposed to represent spaces with hyphens or underscores).

waldoj commented 10 years ago

The problem here appears to lie in WordPress's list_filter() function.

waldoj commented 10 years ago

As it turns out, the problem is a lot deeper than that. The problem is within query(), which doesn't sanitize column names as it compares them to the input in the URL. So region code isn't matched to region_code, and it's discarded.

That's fixed pretty easily, like such:

// Fill in any defaults that are missing.
$query_vars = $this->get_query_vars( $data );
foreach ($query_vars as $key => $value) {
   unset($query_vars[$key]);
   $query_vars[ str_replace(' ', '_', $key) ] = $value;
}

Then the problem is with list_filter(), because that also isn't making the proper comparison. So I've gotten partway done with this, but there's more to do.