Methods

Class/Module Index [+]

Quicksearch

HTMLConformanceChecker

Public Class Methods

new(stream, *args) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 267
def initialize(stream, *args)
  super(HTML5::HTMLTokenizer.new(stream, *args))
  @things_that_define_an_id    = []
  @things_that_point_to_an_id  = []
  @ids_we_have_known_and_loved = []
end

Public Instance Methods

check_attribute_values(token) click to toggle source

Attribute validation

# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 655
def check_attribute_values(token)
  tag_name = token.fetch(:name, "")
  for attr_name, attr_value in token.fetch(:data, [])
    attr_name = attr_name.downcase
    method = "validate_attribute_value_#{tag_name.to_s.underscore}_#{attr_name.to_s.underscore}"
    if respond_to?(method)
      send(method, token, tag_name, attr_name, attr_value) do |t|
        yield t
      end
    else
      method = "validate_attribute_value_#{attr_name.to_s.underscore}"
      if respond_to?(method)
        send(method, token, tag_name, attr_name, attr_value) do |t|
          yield t
        end
      end
    end
  end
end
check_boolean(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 514
def check_boolean(token, tag_name, attr_name, attr_value)
  enumerated_values = [attr_name, '']
  if !enumerated_values.include?(attr_value)
    yield( {:type => "ParseError",
         :data => "invalid-boolean-value",
         :datavars => {"tagName" => tag_name,
              "attributeName" => attr_name,
              "enumeratedValues" => enumerated_values}})
    yield( {:type => "ParseError",
         :data => "invalid-attribute-value",
         :datavars => {"tagName" => tag_name,
              "attributeName" => attr_name}})
  end
end
check_browsing_context(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 581
def check_browsing_context(token, tag_name, attr_name, attr_value)
  return if not attr_value
  return if attr_value[0] != __
  attr_value.downcase!
  return if ['_self', '_parent', '_top', '_blank'].include?(attr_value)
  yield({:type => "ParseError",
       :data => "invalid-browsing-context",
       :datavars => {"tagName" => tag_name,
            "attributeName" => attr_name}})
end
check_date_time(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 640
  def check_date_time(token, tag_name, attr_name, attr_value)
    # XXX
    state = 'begin' # ('begin', '...
#    for c in attr_value
#      if state == 'begin' =>
#        if SPACE_CHARACTERS.include?(c)
#          continue
#        elsif digits.include?(c)
#          state = ...
  end
check_enumerated_value(token, tag_name, attr_name, attr_value, enumerated_values) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 492
def check_enumerated_value(token, tag_name, attr_name, attr_value, enumerated_values)
  if !attr_value || attr_value.length == 0
    yield( {:type => "ParseError",
         :data => "attribute-value-can-not-be-blank",
         :datavars => {"tagName" => tag_name,
              "attributeName" => attr_name}})
    return
  end
  attr_value.downcase!
  if !enumerated_values.include?(attr_value)
    yield( {:type => "ParseError",
         :data => "invalid-enumerated-value",
         :datavars => {"tagName" => tag_name,
              "attribute_name" => attr_name,
              "enumeratedValues" => enumerated_values}})
    yield( {:type => "ParseError",
         :data => "invalid-attribute-value",
         :datavars => {"tagName" => tag_name,
              "attributeName" => attr_name}})
  end
end
check_floating_point_number(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 577
def check_floating_point_number(token, tag_name, attr_name, attr_value)
  # XXX
end
check_id(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 429
def check_id(token, tag_name, attr_name, attr_value)
  if !attr_value || attr_value.length == 0
    yield({:type => "ParseError",
            :data => "attribute-value-can-not-be-blank",
            :datavars => {"tagName" => tag_name,
              "attributeName" => attr_name}})
  end
  attr_value.each_byte do |b|
    c = [b].pack('c*')
    if HTML5::SPACE_CHARACTERS.include?(c)
      yield( {:type => "ParseError",
           :data => "space-in-id",
           :datavars => {"tagName" => tag_name,
                "attributeName" => attr_name}})
      yield( {:type => "ParseError",
           :data => "invalid-attribute-value",
           :datavars => {"tagName" => tag_name,
                "attributeName" => attr_name}})
      break
    end
  end
end
check_integer(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 529
def check_integer(token, tag_name, attr_name, attr_value)
  sign = 1
  number_string = ''
  state = 'begin' # ('begin', 'initial-number', 'number', 'trailing-junk')
  error = {:type => "ParseError",
       :data => "invalid-integer-value",
       :datavars => {"tagName" => tag_name,
              "attributeName" => attr_name,
              "attributeValue" => attr_value}}
  attr_value.scan(/./) do |c|
    if state == 'begin'
      if HTML5::SPACE_CHARACTERS.include?(c)
        next
      elsif c == '-'
        sign  = -1
        state = 'initial-number'
      elsif HTML5::DIGITS.include?(c)
        number_string += c
        state = 'in-number'
      else
        yield error
        return
      end
    elsif state == 'initial-number'
      if !HTML5::DIGITS.include?(c)
        yield error
        return
      end
      number_string += c
      state = 'in-number'
    elsif state == 'in-number'
      if HTML5::DIGITS.include?(c)
        number_string += c
      else
        state = 'trailing-junk'
      end
    elsif state == 'trailing-junk'
      next
    end
  end
  if number_string.length == 0
    yield( {:type => "ParseError",
         :data => "attribute-value-can-not-be-blank",
         :datavars => {"tagName" => tag_name,
              "attributeName" => attr_name}})
  end
end
check_iri(token, tag_name, attr_name, attr_value) click to toggle source

def checkURI(token, tag_name, attr_name, attr_value)

is_valid, error_code = rfc3987.is_valid_uri(attr_value)
if not is_valid
  yield {:type => "ParseError",
       :data => error_code,
       :datavars => {"tagName" => tag_name,
            "attributeName" => attr_name}}
  yield {:type => "ParseError",
       :data => "invalid-attribute-value",
       :datavars => {"tagName" => tag_name,
            "attributeName" => attr_name}}
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 415
def check_iri(token, tag_name, attr_name, attr_value)
  is_valid, error_code = is_valid_iri(attr_value)
  if !is_valid
    yield({:type => "ParseError",
           :data => error_code,
           :datavars => {"tagName" => tag_name,
              "attributeName" => attr_name}})
    yield({:type => "ParseError",
           :data => "invalid-attribute-value",
           :datavars => {"tagName" => tag_name,
              "attributeName" => attr_name}})
  end
end
check_lang_code(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 592
def check_lang_code(token, tag_name, attr_name, attr_value)
  return if !attr_value || attr_value == '' # blank is OK
  if not is_valid_lang_code(attr_value)
    yield( {:type => "ParseError",
         :data => "invalid-lang-code",
         :datavars => {"tagName" => tag_name,
              "attributeName" => attr_name,
              "attributeValue" => attr_value}})
  end
end
check_media_query(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 620
def check_media_query(token, tag_name, attr_name, attr_value)
  # XXX
end
check_mime_type(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 603
def check_mime_type(token, tag_name, attr_name, attr_value)
  # XXX needs tests
  if not attr_value
    yield( {:type => "ParseError",
         :data => "attribute-value-can-not-be-blank",
         :datavars => {"tagName" => tag_name,
              "attributeName" => attr_name}})
  end
  if not is_valid_mime_type(attr_value)
    yield( {:type => "ParseError",
         :data => "invalid-mime-type",
         :datavars => {"tagName" => tag_name,
              "attributeName" => attr_name,
              "attributeValue" => attr_value}})
  end
end
check_start_tag_required_attributes(token) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 369
def check_start_tag_required_attributes(token)
  # check for presence of required attributes
  name = (token[:name] || "").downcase
  if @@required_attribute_map.keys().include?(name)
    attrs_present = (token[:data] || []).collect{|t| t[0]}
    for attr_name in @@required_attribute_map[name]
      if !attrs_present.include?(attr_name)
        yield( {:type => "ParseError",
             :data => "missing-required-attribute",
             :datavars => {"tagName" => name,
                  "attributeName" => attr_name}})
      end
    end
  end
end
check_start_tag_unknown_attributes(token) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 385
def check_start_tag_unknown_attributes(token)
  # check for recognized attribute names
  name = token[:name].downcase
  allowed_attributes = @@global_attributes | @@allowed_attribute_map.fetch(name, [])
  for attr_name, attr_value in token.fetch(:data, [])
    if !allowed_attributes.include?(attr_name.downcase())
      yield( {:type => "ParseError",
           :data => "unknown-attribute",
           :datavars => {"tagName" => name,
                "attributeName" => attr_name}})
    end
  end
end
check_token_list(tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 472
def check_token_list(tag_name, attr_name, attr_value)
  # The "token" in the method name refers to tokens in an attribute value
  # i.e. http://www.whatwg.org/specs/web-apps/current-work/#set-of
  # but the "token" parameter refers to the token generated from
  # HTMLTokenizer.  Sorry for the confusion.
  value_list = parse_token_list(attr_value)
  value_dict = {}
  for current_value in value_list
    if value_dict.has_key?(current_value)
      yield({:type => "ParseError",
           :data => "duplicate-value-in-token-list",
           :datavars => {"tagName" => tag_name,
                "attributeName" => attr_name,
                "attributeValue" => current_value}})
      break
    end
    value_dict[current_value] = 1
  end
end
check_unknown_start_tag(token) click to toggle source

Start tag validation helpers

# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 359
def check_unknown_start_tag(token)
  # check for recognized tag name
  name = (token[:name] || "").downcase
  if !@@allowed_attribute_map.keys.include?(name)
    yield({:type => "ParseError",
           :data => "unknown-start-tag",
           :datavars => {"tagName" => name}})
  end
end
each() click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 274
def each
  __getobj__.each do |token|
    method = "validate_#{token.fetch(:type, '-').to_s.underscore}_#{token.fetch(:name, '-').to_s.underscore}"
    if respond_to?(method)
      send(method, token){|t| yield t }
    else
      method = "validate_#{token.fetch(:type, '-').to_s.underscore}"
      if respond_to?(method)
        send(method, token) do |t|
          yield t
        end
      end
    end
    yield token
  end
  eof do |t|
    yield t
  end
end
eof() click to toggle source

Whole document validation (IDs, etc.)

# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 801
def eof
  for token in @things_that_point_to_an_id
    tag_name = token.fetch(:name, "").downcase
    attrs_dict = token[:data] # by now html5parser has "normalized" the attrs list into a dict.
                  # hooray for obscure side effects!
    attr_value = attrs_dict.fetch("contextmenu", "")
    if attr_value and (!@ids_we_have_known_and_loved.include?(attr_value))
      yield( {:type => "ParseError",
           :data => "id-does-not-exist",
           :datavars => {"tagName" => tag_name,
                "attributeName" => "contextmenu",
                "attributeValue" => attr_value}})
    else
      for ref_token in @things_that_define_an_id
        id = ref_token.fetch(:data, {}).fetch("id", "")
        if not id
          continue
        end
        if id == attr_value
          if ref_token.fetch(:name, "").downcase != "men"
            yield( {:type => "ParseError",
                 :data => "contextmenu-must-point-to-menu"})
          end
          break
        end
      end
    end
  end
end
parse_token_list(value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 452
def parse_token_list(value)
  valueList = []
  currentValue = ''
  (value + ' ').each_byte do |b|
    c = [b].pack('c*')
    if HTML5::SPACE_CHARACTERS.include?(c)
      if currentValue.length > 0
        valueList << currentValue
        currentValue = ''
      end
    else
      currentValue += c
    end
  end
  if currentValue.length > 0
    valueList << currentValue
  end
  valueList
end
validate_attribute_value_a_href(token, tag_name, attr_name, attr_value) click to toggle source

XXX need tests from here on

Alias for: check_iri
validate_attribute_value_a_hreflang(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_lang_code
validate_attribute_value_a_media(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_media_query
validate_attribute_value_a_ping(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 769
def validate_attribute_value_a_ping(token, tag_name, attr_name, attr_value)
  value_list = parse_token_list(attr_value)
  for current_value in value_list
    checkIRI(token, tag_name, attr_name, attr_value) do |t|
      yield t
    end
  end
end
validate_attribute_value_a_rel(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_link_relation
validate_attribute_value_a_target(token, tag_name, attr_name, attr_value) click to toggle source
validate_attribute_value_a_type(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_mime_type
validate_attribute_value_base_href(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_iri
validate_attribute_value_base_target(token, tag_name, attr_name, attr_value) click to toggle source
validate_attribute_value_blockquote_cite(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_iri
validate_attribute_value_class(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 675
def validate_attribute_value_class(token, tag_name, attr_name, attr_value)
  check_token_list(tag_name, attr_name, attr_value) do |t|
    yield t
    yield( {:type => "ParseError",
         :data => "invalid-attribute-value",
         :datavars => {"tagName" => tag_name,
              "attributeName" => attr_name}})
  end
end
validate_attribute_value_contenteditable(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 685
def validate_attribute_value_contenteditable(token, tag_name, attr_name, attr_value)
  check_enumerated_value(token, tag_name, attr_name, attr_value, ['true', 'false', '']) do |t|
    yield t
  end
end
validate_attribute_value_contextmenu(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 706
def validate_attribute_value_contextmenu(token, tag_name, attr_name, attr_value)
  check_id(token, tag_name, attr_name, attr_value) do |t|
    yield t
  end
  @things_that_point_to_an_id << token
end
validate_attribute_value_del_cite(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_iri
validate_attribute_value_del_datetime(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_date_time
validate_attribute_value_dir(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 691
def validate_attribute_value_dir(token, tag_name, attr_name, attr_value)
  check_enumerated_value(token, tag_name, attr_name, attr_value, ['ltr', 'rtl']) do |t|
    yield t
  end
end
validate_attribute_value_draggable(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 697
def validate_attribute_value_draggable(token, tag_name, attr_name, attr_value)
  check_enumerated_value(token, tag_name, attr_name, attr_value, ['true', 'false']) do |t|
    yield t
  end
end
validate_attribute_value_html_xmlns(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 742
def validate_attribute_value_html_xmlns(token, tag_name, attr_name, attr_value)
  if attr_value != "http://www.w3.org/1999/xhtml"
    yield( {:type => "ParseError",
         :data => "invalid-root-namespace",
         :datavars => {"tagName" => tag_name,
              "attributeName" => attr_name}})
  end
end
validate_attribute_value_id(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 713
def validate_attribute_value_id(token, tag_name, attr_name, attr_value)
  # This method has side effects.  It adds 'token' to the list of
  # things that define an ID (@things_that_define_an_id) so that we can
  # later check 1) whether an ID is duplicated, and 2) whether all the
  # things that point to something else by ID (like <label for> or
  # <span contextmenu>) point to an ID that actually exists somewhere.
  check_id(token, tag_name, attr_name, attr_value) do |t|
    yield t
  end
  return if not attr_value
  if @ids_we_have_known_and_loved.include?(attr_value)
    yield( {:type => "ParseError",
         :data => "duplicate-id",
         :datavars => {"tagName" => tag_name}})
  end
  @ids_we_have_known_and_loved << attr_value
  @things_that_define_an_id << token
end
validate_attribute_value_ins_cite(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_iri
validate_attribute_value_ins_datetime(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_date_time
validate_attribute_value_irrelevant(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_boolean
validate_attribute_value_lang(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_lang_code
validate_attribute_value_li_value(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_integer
validate_attribute_value_meter_high(token, tag_name, attr_name, attr_value) click to toggle source
validate_attribute_value_meter_low(token, tag_name, attr_name, attr_value) click to toggle source
validate_attribute_value_meter_max(token, tag_name, attr_name, attr_value) click to toggle source
validate_attribute_value_meter_min(token, tag_name, attr_name, attr_value) click to toggle source
validate_attribute_value_meter_optimum(token, tag_name, attr_name, attr_value) click to toggle source
validate_attribute_value_meter_value(token, tag_name, attr_name, attr_value) click to toggle source
validate_attribute_value_ol_start(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_integer
validate_attribute_value_progress_max(token, tag_name, attr_name, attr_value) click to toggle source
validate_attribute_value_progress_value(token, tag_name, attr_name, attr_value) click to toggle source
validate_attribute_value_q_cite(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_iri
validate_attribute_value_ref(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 734
def validate_attribute_value_ref(token, tag_name, attr_name, attr_value)
  # XXX
end
validate_attribute_value_style_media(token, tag_name, attr_name, attr_value) click to toggle source

XXX <meta> attributes

Alias for: check_media_query
validate_attribute_value_style_scoped(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_boolean
validate_attribute_value_style_type(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_mime_type
validate_attribute_value_tabindex(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_integer
validate_attribute_value_template(token, tag_name, attr_name, attr_value) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 738
def validate_attribute_value_template(token, tag_name, attr_name, attr_value)
  # XXX
end
validate_attribute_value_time_datetime(token, tag_name, attr_name, attr_value) click to toggle source
Alias for: check_date_time
validate_start_tag(token) click to toggle source

Start tag validation

# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 298
def validate_start_tag(token)
  check_unknown_start_tag(token){|t| yield t}
  check_start_tag_required_attributes(token) do |t|
    yield t
  end
  check_start_tag_unknown_attributes(token) do |t|
    yield t
  end
  check_attribute_values(token) do |t|
    yield t
  end
end
validate_start_tag_embed(token) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 311
def validate_start_tag_embed(token)
  check_start_tag_required_attributes(token) do |t|
    yield t
  end
  check_attribute_values(token) do |t|
    yield t
  end
  # spec says "any attributes w/o namespace"
  # so don't call check_start_tag_unknown_attributes
end
validate_start_tag_input(token) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 322
def validate_start_tag_input(token)
  check_attribute_values(token) do |t|
    yield t
  end
  attr_dict = Hash[*token[:data].collect{|(name, value)| [name.downcase, value]}.flatten]
  input_type = attr_dict.fetch('type', "text")
  if !@@input_type_allowed_attribute_map.keys().include?(input_type)
    yield({:type => "ParseError",
         :data => "unknown-input-type",
         :datavars => {:attrValue => input_type}})
  end
  allowed_attributes = @@input_type_allowed_attribute_map.fetch(input_type, [])
  attr_dict.each do |attr_name, attr_value|
    if !@@allowed_attribute_map['input'].include?(attr_name)
      yield({:type => "ParseError",
           :data => "unknown-attribute",
           :datavars => {"tagName" => "input",
                "attributeName" => attr_name}})
    elsif !allowed_attributes.include?(attr_name)
      yield({:type => "ParseError",
           :data => "attribute-not-allowed-on-this-input-type",
           :datavars => {"attributeName" => attr_name,
                "inputType" => input_type}})
    end
    if @@input_type_deprecated_attribute_map.fetch(input_type, []).include?(attr_name)
      yield({:type => "ParseError",
           :data => "deprecated-attribute",
           :datavars => {"attributeName" => attr_name,
                "inputType" => input_type}})
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.