Method: HTML5::HTMLTokenizer#attribute_name_state

Defined in:
lib/html5/tokenizer.rb

#attribute_name_stateObject



444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
# File 'lib/html5/tokenizer.rb', line 444

def attribute_name_state
  data = @stream.char
  leavingThisState = true
  emitToken = false
  if data == "="
    @state = :before_attribute_value_state
  elsif data == :EOF
    @token_queue << {:type => :ParseError, :data => "eof-in-attribute-name"}
    @state = :data_state
    emitToken = true
  elsif ASCII_LETTERS.include? data
    @current_token[:data][-1][0] += data + @stream.chars_until(ASCII_LETTERS, true)
    leavingThisState = false
  elsif data == ">"
    # XXX If we emit here the attributes are converted to a dict
    # without being checked and when the code below runs we error
    # because data is a dict not a list
    emitToken = true
  elsif SPACE_CHARACTERS.include? data
    @state = :after_attribute_name_state
  elsif data == "/"
    process_solidus_in_tag
    @state = :before_attribute_name_state
  else
    @current_token[:data][-1][0] += data
    leavingThisState = false
  end

  if leavingThisState
    # Attributes are not dropped at this stage. That happens when the
    # start tag token is emitted so values can still be safely appended
    # to attributes, but we do want to report the parse error in time.
    if @lowercase_attr_name
        @current_token[:data][-1][0] = @current_token[:data].last.first.downcase
    end
    @current_token[:data][0...-1].each {|name,value|
      if @current_token[:data].last.first == name
        @token_queue << {:type => :ParseError, :data => "duplicate-attribute"}
        break # don't report an error more than once
      end
    }
    # XXX Fix for above XXX
    emit_current_token if emitToken
  end
  return true
end