fixed issue with xml signature reading

This commit is contained in:
bvn13 2023-03-26 18:44:09 +03:00
parent c1497dc29c
commit 7115d3b2d6
4 changed files with 28821 additions and 8 deletions

View File

@ -10,6 +10,10 @@ Official GPX format is on [topografix](https://www.topografix.com/GPX/1/1/) site
## Changelog
### 2023-03-26
1) Fixed signature reading
### 2023-02-13
1) Fixed missed extensions

View File

@ -33,9 +33,7 @@ class GpxReader {
.trim()
.replace("'", "\"")
.replace(" ?", "?")
if (GpxConstant.HEADER != signaturePrepared
&& GpxConstant.HEADER_EXTENDED != signaturePrepared
) {
if (!signaturePrepared.startsWith("<?xml") || !signaturePrepared.endsWith("?>")) {
throw IllegalArgumentException("Wrong xml signature!")
}
return readBeginning(dis, Container.empty(container.position))

View File

@ -430,4 +430,84 @@ class GpxReaderTest {
Assertions.assertEquals(20, gpxType.trk?.get(0)?.trkseg?.get(0)?.trkpt?.size ?: 0)
Assertions.assertEquals(4, gpxType.trk?.get(0)?.trkseg?.get(0)?.trkpt?.get(0)?.extensions?.size ?: 0)
}
@DisplayName("Read track-2023-03-09--21-10-54.gpx")
@Test
fun readTestGpx_v_1_10_3() {
val gpxType = GpxType.read(javaClass.classLoader.getResource("track-2023-03-09--21-10-54.gpx").openStream())
Assertions.assertEquals(4, gpxType.trk?.get(0)?.trkseg?.get(0)?.trkpt?.get(0)?.extensions?.size ?: 0)
}
@DisplayName("test xml signature")
@Test
fun testXmlSignature() {
val gpx = """<gpx
xmlns="http://www.topografix.com/GPX/1/1"
version="1.1"
creator="me.bvn13.sdk.android.gpx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<time>2022-09-24T15:04:00+03:00</time>
<metadata>
<name>test name</name>
<desc></desc>
<author>
<name></name>
</author>
</metadata>
<trk>
<name>track1</name>
<trkseg>
<trkpt lat="123.0" lon="321.0">
</trkpt>
</trkseg>
</trk>
</gpx>"""
GpxType.read("""
<?xml version="1.0" standalone="yes" encoding="UTF-8"?>
$gpx
""".trim()
.lineSequence()
.map {
it.trim()
}
.joinToString("\n")
.byteInputStream()
)
GpxType.read("""
<?xml version="1.0" encoding="UTF-8"?>
$gpx
""".trim()
.lineSequence()
.map {
it.trim()
}
.joinToString("\n")
.byteInputStream()
)
GpxType.read(
"""
<?xml version="1.0"?>
$gpx
""".trim()
.lineSequence()
.map {
it.trim()
}
.joinToString("\n")
.byteInputStream()
)
GpxType.read(
"""
<?xml?>
$gpx
""".trim()
.lineSequence()
.map {
it.trim()
}
.joinToString("\n")
.byteInputStream()
)
}
}

File diff suppressed because it is too large Load Diff