Skip to content

Commit

Permalink
#186 - LENIENT mode allows GPX tags without creator attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
r-follador committed Dec 28, 2024
1 parent 2381b42 commit a46b37a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ The library is licensed under the [Apache License, Version 2.0](http://www.apach

## Release notes

#### Improvements

* [#186](https://github.com/jenetics/jpx/issues/186): LENIENT mode allows GPX tags without creator attributes.

### 3.2.1

### [3.2.0](https://github.com/jenetics/jpx/releases/tag/v3.2.0)

#### Improvements
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Env.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object Env {
* Information about the library and author.
*/
object JPX {
const val VERSION = "3.2.0"
const val VERSION = "3.2.1"
const val ID = "jpx"
const val NAME = "jpx"
const val GROUP = "io.jenetics"
Expand Down
4 changes: 2 additions & 2 deletions jpx/src/main/java/io/jenetics/jpx/GPX.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public static Version of(final String version) {
* @param routes the routes
* @param tracks the tracks
* @param extensions the XML extensions document
* @throws NullPointerException if the {@code creator} or {@code version} is
* @throws NullPointerException if the {@code version} is
* {@code null}
*/
private GPX(
Expand All @@ -322,7 +322,7 @@ private GPX(
final Document extensions
) {
_version = requireNonNull(version);
_creator = requireNonNull(creator);
_creator = creator;
_metadata = metadata;
_wayPoints = copyOf(wayPoints);
_routes = copyOf(routes);
Expand Down
27 changes: 27 additions & 0 deletions jpx/src/test/java/io/jenetics/jpx/GPXTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -960,4 +960,31 @@ public void issue170_InvalidGPXVersion() throws IOException {
assertThat(gpx.getTracks().get(0).getSegments().get(0)).hasSize(2);
}

@Test
public void issue186_MissingCreator() throws IOException {
final var resource = "/io/jenetics/jpx/ISSUE-186.gpx";
final GPX gpx_lenient;
try (InputStream in = getClass().getResourceAsStream(resource)) {
gpx_lenient = GPX.Reader.of(Mode.LENIENT).read(in);
}

assertThat(gpx_lenient.getVersion()).isEqualTo("1.1");
assertThat(gpx_lenient.getCreator()).isNull();
assertThat(gpx_lenient.getTracks()).hasSize(1);
assertThat(gpx_lenient.getTracks().get(0).getSegments()).hasSize(1);
assertThat(gpx_lenient.getTracks().get(0).getSegments().get(0)).hasSize(9);


try (InputStream in = getClass().getResourceAsStream("/path/to/resource")) {
GPX.Reader.of(Mode.STRICT).read(in);
Assert.fail("Expected InvalidObjectException to be thrown.");
} catch (NullPointerException e) {
// Expected to fail in STRICT mode, as Creator attribute is missing
} catch (Exception e) {
Assert.fail("Unexpected exception was thrown: " + e);
}


}

}
16 changes: 16 additions & 0 deletions jpx/src/test/resources/io/jenetics/jpx/ISSUE-186.gpx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<gpx version="1.1">
<trk>
<trkseg>
<trkpt lat="47.1849902" lon="9.3118156"><ele>1411.7906106047938</ele><time>2018-09-30T09:43:37Z</time></trkpt>
<trkpt lat="47.1847356" lon="9.3116516"><ele>1392.486126435269</ele><time>2018-09-30T09:44:41Z</time></trkpt>
<trkpt lat="47.1844677" lon="9.3115969"><ele>1395.0386210201773</ele><time>2018-09-30T09:45:09Z</time></trkpt>
<trkpt lat="47.1841943" lon="9.3116178"><ele>1399.1852111777555</ele><time>2018-09-30T09:45:39Z</time></trkpt>
<trkpt lat="47.1839262" lon="9.311698"><ele>1400.9042412783833</ele><time>2018-09-30T09:46:06Z</time></trkpt>
<trkpt lat="47.1836688" lon="9.3118495"><ele>1404.8712068295272</ele><time>2018-09-30T09:46:30Z</time></trkpt>
<trkpt lat="47.1834009" lon="9.3119155"><ele>1406.7036626781644</ele><time>2018-09-30T09:46:56Z</time></trkpt>
<trkpt lat="47.1831309" lon="9.3119291"><ele>1408.6363346678631</ele><time>2018-09-30T09:47:24Z</time></trkpt>
<trkpt lat="47.18286" lon="9.311905"><ele>1410.9618086711207</ele><time>2018-09-30T09:47:48Z</time></trkpt>
</trkseg>
</trk>
</gpx>

0 comments on commit a46b37a

Please sign in to comment.