Skip to content

Commit 8f64c15

Browse files
authored
UTF-8 enhancement (#11)
1 parent 5e18cca commit 8f64c15

4 files changed

Lines changed: 46 additions & 5 deletions

File tree

readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ $feature = $geoserver->upload($file);
190190
// OneOffTech\GeoServer\Models\Resource
191191
```
192192

193+
> For file character encoding please refer to [File Character Encoding](#file-character-encoding)
194+
193195
Once uploaded, the return value will be an instance of the `OneOffTech\GeoServer\Models\Resource`.
194196
It contains the details extracted by the GeoServer, like the bounding box.
195197

@@ -320,6 +322,21 @@ $isSupported = StyleFile::isSupported($path);
320322
> For example `Geojson`, `KML` and `GPX` are not supported out-of-the-box by GeoServer,
321323
> although plugins might be available for doing that
322324
325+
## File Character Encoding
326+
327+
GeoServer can deal with character encoding of layers/features, but tests highlighted
328+
a limited support when using UTF-8 for data/coverage store names.
329+
330+
To prevent issues with UTF-8 features attributes, the client set the character encoding
331+
to UTF-8 when uploading a file. In this way GeoServer will consider UTF-8 as the
332+
character encoding for features/attributes contained in the file. This do not affect
333+
layer or store names.
334+
335+
As by design decision the store name is the filename, or the assigned name when
336+
performing the upload, we highly reccomend to use ASCII characters for it.
337+
Use of UTF-8 encoded filenames (or store name) might prevent the client to retrieve the
338+
store/layer corresponding to the uploaded file.
339+
323340
## Testing
324341

325342
The library is covered with unit and integration tests.

src/GeoServer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public function deleteCoveragestore($name)
293293
public function upload(GeoFile $file)
294294
{
295295
$store = GeoType::storeFor($file->type);
296-
$route = $this->routes->url("workspaces/$this->workspace/$store/$file->name/file.{$file->normalizedExtension}");
296+
$route = $this->routes->url("workspaces/$this->workspace/$store/$file->name/file.{$file->normalizedExtension}?charset=UTF-8");
297297

298298
// if ZIP shpefile and name was changed from original filename
299299
// we need to rename all files contained in it

tests/Integration/GeoServerDataStoresTest.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,37 @@ public function test_shapefile_in_zip_archive_can_be_uploaded_and_deleted()
145145
$this->assertEquals(69.3082, $feature->boundingBox->maxX);
146146
$this->assertEquals(34.57558, $feature->boundingBox->maxY);
147147

148-
// $this->assertTrue($this->geoserver->exist($data), "Data not existing after upload");
148+
$this->assertTrue($this->geoserver->exist($data), "Data not existing after upload");
149149

150-
// $deleteResult = $this->geoserver->remove($data);
150+
$deleteResult = $this->geoserver->remove($data);
151151

152-
// $this->assertTrue($deleteResult, "GeoFile not deleted");
152+
$this->assertTrue($deleteResult, "GeoFile not deleted");
153153

154-
// $this->assertFalse($this->geoserver->exist($data), "Data still exists after remove");
154+
$this->assertFalse($this->geoserver->exist($data), "Data still exists after remove");
155+
}
156+
157+
public function test_utf8_shapefile_in_zip_archive_can_be_uploaded_and_deleted()
158+
{
159+
$datastoreName = 'shapefile-utf8-inside';
160+
$data = GeoFile::from(__DIR__ . '/../fixtures/some_shapefile_with_cyrillicйфячыцус.zip')->name($datastoreName);
161+
162+
$feature = $this->geoserver->upload($data);
163+
164+
$this->assertInstanceOf(Feature::class, $feature);
165+
$this->assertEquals(GeoType::VECTOR, $feature->type());
166+
$this->assertEquals($datastoreName, $feature->name);
167+
$this->assertEquals($datastoreName, $feature->title);
168+
$this->assertEquals($datastoreName, $feature->nativeName);
169+
$this->assertEquals("EPSG:3857", $feature->srs);
170+
$this->assertTrue($feature->enabled);
171+
172+
$this->assertTrue($this->geoserver->exist($data), "Data not existing after upload");
173+
174+
$deleteResult = $this->geoserver->remove($data);
175+
176+
$this->assertTrue($deleteResult, "GeoFile not deleted");
177+
178+
$this->assertFalse($this->geoserver->exist($data), "Data still exists after remove");
155179
}
156180

157181
public function test_shapefile_in_zip_archive_can_be_renamed_during_upload_and_deleted()
2.33 KB
Binary file not shown.

0 commit comments

Comments
 (0)