Skip to content

Commit eea05ee

Browse files
committed
Merge branch 'master' into develop
2 parents 2720aa9 + 43f1136 commit eea05ee

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

doc/release-notes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
## [0.4.0](https://github.com/NetTopologySuite/NetTopologySuite.IO.GPX/milestone/7)
44
*Nothing yet...*
55

6+
## [0.3.2](https://github.com/NetTopologySuite/NetTopologySuite.IO.GPX/milestone/9)
7+
- The opt-in `GpxReaderSettings.AllowMissingVersionAttribute` property added in 0.3.1 has been replaced by `IgnoreVersionAttribute`, which enables the same situations as `AllowMissingVersionAttribute` did, plus situations where `version` was specified as something other than `version='1.1'` ([#28](https://github.com/NetTopologySuite/NetTopologySuite.IO.GPX/issues/28)).
8+
69
## [0.3.1](https://github.com/NetTopologySuite/NetTopologySuite.IO.GPX/milestone/8)
710
- `GpxReaderSettings` now has an opt-in `AllowMissingVersionAttribute` property, to allow reading files without a `version` attribute ([#27](https://github.com/NetTopologySuite/NetTopologySuite.IO.GPX/issues/27)).
811

src/NetTopologySuite.IO.GPX/GpxReader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ public static void Read(XmlReader reader, GpxReaderSettings settings, GpxVisitor
100100
settings = settings ?? new GpxReaderSettings();
101101
while (reader.ReadToFollowing("gpx", Helpers.GpxNamespace))
102102
{
103-
bool versionAccepted = settings.AllowMissingVersionAttribute;
103+
string version = null;
104104
string creator = settings.DefaultCreatorIfMissing;
105105
for (bool hasAttribute = reader.MoveToFirstAttribute(); hasAttribute; hasAttribute = reader.MoveToNextAttribute())
106106
{
107107
switch (reader.Name)
108108
{
109109
case "version":
110-
versionAccepted = reader.Value == "1.1";
110+
version = reader.Value;
111111
break;
112112

113113
case "creator":
@@ -116,7 +116,7 @@ public static void Read(XmlReader reader, GpxReaderSettings settings, GpxVisitor
116116
}
117117
}
118118

119-
if (!versionAccepted)
119+
if (version != "1.1" && !settings.IgnoreVersionAttribute)
120120
{
121121
throw new XmlException("'version' must be '1.1'");
122122
}

src/NetTopologySuite.IO.GPX/GpxReaderSettings.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public sealed class GpxReaderSettings
3434
public string DefaultCreatorIfMissing { get; set; }
3535

3636
/// <summary>
37-
/// Gets or sets a value indicating whether or not to ignore a missing <c>version="1.1"</c>
38-
/// declaration, even though such files would not pass XSD validation (see
39-
/// NetTopologySuite/NetTopologySuite.IO.GPX#27).
37+
/// Gets or sets a value indicating whether or not to ignore files that do not contain
38+
/// <c>version="1.1"</c> exactly, even though such files would not pass XSD validation (see
39+
/// NetTopologySuite/NetTopologySuite.IO.GPX#27 and #28).
4040
/// </summary>
41-
public bool AllowMissingVersionAttribute { get; set; }
41+
public bool IgnoreVersionAttribute { get; set; }
4242
}
4343
}

tests/NetTopologySuite.IO.GPX.Tests/GpxFileTests.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,10 @@ public void RoundTripForValuesVeryNearZeroShouldSucceed()
182182
[InlineData("<trk><trkseg><trkpt lat='1' lon='1'><ele>Infinity</ele></trkpt></trkseg></trk>")]
183183
public void ParseWithInfiniteWaypointElevationShouldFail(string inner)
184184
{
185-
Assert.ThrowsAny<XmlException>(() => GpxFile.Parse("<gpx xmlns='http://www.topografix.com/GPX/1/1' version='1.1' creator='airbreather'>" + inner + "</gpx>", null));
185+
Assert.ThrowsAny<XmlException>(() => GpxFile.Parse($"<gpx xmlns='http://www.topografix.com/GPX/1/1' version='1.1' creator='airbreather'>{inner}</gpx>", null));
186186
}
187187

188188
[Theory]
189-
[GitHubIssue(23, 27)]
190189
[InlineData("<gpx xmlns='http://www.topografix.com/GPX/1/1' />")]
191190
[InlineData("<gpx xmlns='http://www.topografix.com/GPX/1/1' version='1.1' />")]
192191
[InlineData("<gpx xmlns='http://www.topografix.com/GPX/1/1' creator='someone' />")]
@@ -219,7 +218,21 @@ public void MissingVersionShouldBeValid_OptIn()
219218
";
220219
Assert.ThrowsAny<XmlException>(() => GpxFile.Parse(GpxText, null));
221220

222-
var settings = new GpxReaderSettings { AllowMissingVersionAttribute = true };
221+
var settings = new GpxReaderSettings { IgnoreVersionAttribute = true };
222+
var file = GpxFile.Parse(GpxText, settings);
223+
Assert.Equal("someone", file.Metadata.Creator);
224+
}
225+
226+
[Fact]
227+
[GitHubIssue(28)]
228+
public void DifferentVersionShouldBeValid_OptIn()
229+
{
230+
const string GpxText = @"
231+
<gpx xmlns='http://www.topografix.com/GPX/1/1' version='1.2' creator='someone' />
232+
";
233+
Assert.ThrowsAny<XmlException>(() => GpxFile.Parse(GpxText, null));
234+
235+
var settings = new GpxReaderSettings { IgnoreVersionAttribute = true };
223236
var file = GpxFile.Parse(GpxText, settings);
224237
Assert.Equal("someone", file.Metadata.Creator);
225238
}

0 commit comments

Comments
 (0)