Class: GpxDoctor::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/gpx_doctor/validator.rb

Constant Summary collapse

ALLOWED_VERSIONS =
%w[1.0 1.1].freeze
DOCTYPE_PATTERN =

Matches a DOCTYPE declaration anywhere in the string (case-insensitive). DOCTYPE is rejected entirely because it can carry external-entity references (XXE) or internal entity bombs (billion-laughs).

/<!DOCTYPE/i.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_string) ⇒ Validator

Returns a new instance of Validator.



20
21
22
# File 'lib/gpx_doctor/validator.rb', line 20

def initialize(xml_string)
  @xml_string = xml_string
end

Class Method Details

.validate!(xml_string) ⇒ Object



15
16
17
# File 'lib/gpx_doctor/validator.rb', line 15

def validate!(xml_string)
  new(xml_string).validate!
end

Instance Method Details

#validate!Object

Raises GpxDoctor::InvalidGpxError if the input is not a valid, safe GPX document.



25
26
27
28
29
30
31
# File 'lib/gpx_doctor/validator.rb', line 25

def validate!
  reject_doctype!
  doc = parse_xml!
  validate_root!(doc)
  validate_version!(doc)
  true
end