@@ -344,7 +344,7 @@ public void TimestampsShouldPreserveFractionalSecondsWithinDefinedPrecision()
344
344
</wpt>
345
345
</gpx>
346
346
" ;
347
- string text = GpxFile . Parse ( GpxText , null ) . BuildString ( null ) ;
347
+ string text = GpxFile . Parse ( GpxText , null ) . BuildString ( null ) ;
348
348
349
349
Assert . Contains ( "1234-05-06T07:08:09.7654321Z" , text ) ;
350
350
Assert . Contains ( "5432-10-10T11:22:33.8765432Z" , text ) ; // DateTime resolution is 100ns, so the value gets rounded to 7 digits
@@ -502,5 +502,99 @@ public void OverlongDataUrisShouldBeAccepted_OptIn(int totalUriLength)
502
502
string text = file . BuildString ( null ) ;
503
503
Assert . Contains ( uriText , text ) ;
504
504
}
505
+
506
+ [ Fact ]
507
+ [ GitHubIssue ( 41 ) ]
508
+ public void BadFileWithIncorrectXmlNode_ShouldThrow ( )
509
+ {
510
+ string gpxText = $@ "
511
+ <gpx version='1.1' creator='S Health_0.2' n0:schemaLocation='http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd' xmlns='http://www.topografix.com/GPX/1/1' n1:xsi='http://www.w3.org/2001/XMLSchema-instance' n1:gpx1='http://www.topografix.com/GPX/1/0' n1:ogt10='http://gpstracker.android.sogeti.n1/GPX/1/0' xmlns:n0='xsi' xmlns:n1='xmlns'>
512
+ <metadate>2020-07-31T03:01:31Z</metadate>
513
+ <trk>
514
+ <name>20200731_090010.gpx</name>
515
+ <trkseg>
516
+ <trkpt lat='32.737328' lon='35.65718'>
517
+ <ele>346.0538</ele>
518
+ <time>2020-07-31T03:01:31Z</time>
519
+ </trkpt>
520
+ </trkseg>
521
+ </trk>
522
+ <exerciseinfo>
523
+ <exercisetype>11007</exercisetype>
524
+ </exerciseinfo>
525
+ </gpx>
526
+ " ;
527
+ Assert . ThrowsAny < XmlException > ( ( ) => GpxFile . Parse ( gpxText , null ) ) ;
528
+ }
529
+
530
+ [ Fact ]
531
+ [ GitHubIssue ( 41 ) ]
532
+ public void BadFileWithIncorrectXmlNode_Ignored_ShouldNotThrow ( )
533
+ {
534
+ string gpxText = $@ "
535
+ <gpx version='1.1' creator='S Health_0.2' n0:schemaLocation='http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd' xmlns='http://www.topografix.com/GPX/1/1' n1:xsi='http://www.w3.org/2001/XMLSchema-instance' n1:gpx1='http://www.topografix.com/GPX/1/0' n1:ogt10='http://gpstracker.android.sogeti.n1/GPX/1/0' xmlns:n0='xsi' xmlns:n1='xmlns'>
536
+ <trk>
537
+ <name>20200731_090010.gpx</name>
538
+ <trkseg>
539
+ <trkpt lat='32.737328' lon='35.65718'>
540
+ <ele>346.0538</ele>
541
+ <time>2020-07-31T03:01:31Z</time>
542
+ </trkpt>
543
+ </trkseg>
544
+ </trk>
545
+ <exerciseinfo>
546
+ <exercisetype>11007</exercisetype>
547
+ </exerciseinfo>
548
+ </gpx>
549
+ " ;
550
+ var gpx = GpxFile . Parse ( gpxText , new GpxReaderSettings { IgnoreBadElements = true } ) ;
551
+ Assert . NotNull ( gpx ) ;
552
+ }
553
+
554
+ [ Fact ]
555
+ [ GitHubIssue ( 41 ) ]
556
+ public void BadFileWithMetadate_Ignored_ShouldNotThrow ( )
557
+ {
558
+ string gpxText = $@ "
559
+ <gpx version='1.1' creator='S Health_0.2' n0:schemaLocation='http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd' xmlns='http://www.topografix.com/GPX/1/1' n1:xsi='http://www.w3.org/2001/XMLSchema-instance' n1:gpx1='http://www.topografix.com/GPX/1/0' n1:ogt10='http://gpstracker.android.sogeti.n1/GPX/1/0' xmlns:n0='xsi' xmlns:n1='xmlns'>
560
+ <metadate>2020-07-31T03:01:31Z</metadate>
561
+ <trk>
562
+ <name>20200731_090010.gpx</name>
563
+ <trkseg>
564
+ <trkpt lat='32.737328' lon='35.65718'>
565
+ <ele>346.0538</ele>
566
+ <time>2020-07-31T03:01:31Z</time>
567
+ </trkpt>
568
+ </trkseg>
569
+ </trk>
570
+ </gpx>
571
+ " ;
572
+ var gpx = GpxFile . Parse ( gpxText , new GpxReaderSettings { IgnoreBadElements = true } ) ;
573
+ Assert . NotNull ( gpx ) ;
574
+ }
575
+
576
+ [ Fact ]
577
+ [ GitHubIssue ( 41 ) ]
578
+ public void MetadataIsNotFirst_ShouldNotHang ( )
579
+ {
580
+ string gpxText = $@ "
581
+ <gpx version='1.1' creator='HarelM' n0:schemaLocation='http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd' xmlns='http://www.topografix.com/GPX/1/1' n1:xsi='http://www.w3.org/2001/XMLSchema-instance' n1:gpx1='http://www.topografix.com/GPX/1/0' n1:ogt10='http://gpstracker.android.sogeti.n1/GPX/1/0' xmlns:n0='xsi' xmlns:n1='xmlns'>
582
+ <trk>
583
+ <name>20200731_090010.gpx</name>
584
+ <trkseg>
585
+ <trkpt lat='32.737328' lon='35.65718'>
586
+ <ele>346.0538</ele>
587
+ <time>2020-07-31T03:01:31Z</time>
588
+ </trkpt>
589
+ </trkseg>
590
+ </trk>
591
+ <metadata>
592
+ <link href='somelink.com' />
593
+ </metadata>
594
+ </gpx>
595
+ " ;
596
+ var gpx = GpxFile . Parse ( gpxText , null ) ;
597
+ Assert . Single ( gpx . Metadata . Links . ToArray ( ) ) ;
598
+ }
505
599
}
506
600
}
0 commit comments