Problem
PointParser::parse() does not validate that points have latitude and longitude. Malformed GPX data with missing lat/lon attributes will produce Point objects with null coordinates, which can cause errors downstream in:
GeoHelper::getRawDistance() — deg2rad(null)
BoundsAnalyzer — comparing null coordinates
- Any distance/elevation calculations
Current code
// src/phpGPX/Parsers/PointParser.php (2.x develop)
$point->latitude = isset($node['lat']) ? ((float) $node['lat']) : null;
$point->longitude = isset($node['lon']) ? ((float) $node['lon']) : null;
// ... continues processing even if both are null
Proposed fix
Return null from PointParser::parse() when a point has no coordinates, and filter nulls in callers:
// PointParser::parse()
$point->latitude = isset($node['lat']) ? ((float) $node['lat']) : null;
$point->longitude = isset($node['lon']) ? ((float) $node['lon']) : null;
if ($point->latitude === null && $point->longitude === null) {
return null;
}
Callers (SegmentParser, RouteParser) need to filter null results:
// SegmentParser::parse() example
foreach ($node->trkpt as $trkpt) {
$point = PointParser::parse($trkpt);
if ($point !== null) {
$segment->points[] = $point;
}
}
Notes
- This is a defensive parsing measure — real-world GPX files occasionally contain malformed points
- The check uses
&& (both null), not || — a point with only one coordinate is also invalid but rarer
Related discussion: #67 (comment)
Problem
PointParser::parse()does not validate that points have latitude and longitude. Malformed GPX data with missinglat/lonattributes will producePointobjects withnullcoordinates, which can cause errors downstream in:GeoHelper::getRawDistance()—deg2rad(null)BoundsAnalyzer— comparingnullcoordinatesCurrent code
Proposed fix
Return
nullfromPointParser::parse()when a point has no coordinates, and filter nulls in callers:Callers (
SegmentParser,RouteParser) need to filter null results:Notes
&&(both null), not||— a point with only one coordinate is also invalid but rarerRelated discussion: #67 (comment)