alphagov/whitehall — pull request #133 by h-lame (2013-01-09 16:19:59+00:00)
Title: Allow kml and ArcGIS attachments

kml is just a simple extension, so we added it to the list of those that are allowed for upload.

ArcGIS is more complex as it's actually a zip file containing at least 3 other file types, but possibly 15 other file types. We don't want to allow people to upload 15 extra random types of file (espcially as one of them is .xml), so we've now got something that looks at the list of the files inside the zip file to see if it looks like an ArcGIS file.

We think a zip is an arcgis file if:

* it has one (and only one) file of each of the following extensions: .shp, .dbf, and .shx
* it has no more than one file of any of the following extensions: .prj, .sbn, .sbx, .fbn, .fbx, .ain, .aih, .ixs, .mxs, .atx, .shp.xml, or .cpg
* it doesn't have any other files

This seems to match the description given here http://en.wikipedia.org/wiki/Shapefile although without seeing a lot of ArcGIS files, it might be too strict. For example, maybe it's common practice to have a readme.txt, or maybe it's common practice to bundle several files up in one zip (e.g. london.xxx vs paris.xxx). It wouldn't be too hard to change though.

In passing I've refactored the code that looks inside zip files to give us the beginnings of a platform for allowing zip files that contain different types of files without simply allowing arbitrary file uploads.