# File lib/html5/liberalxmlparser.rb, line 27
    def normalize_token(token)
      case token[:type]
      when :StartTag, :EmptyTag
        # We need to remove the duplicate attributes and convert attributes
        # to a Hash so that [["x", "y"], ["x", "z"]] becomes {"x": "y"}

        token[:data] = Hash[*token[:data].reverse.flatten]

        # For EmptyTags, process both a Start and an End tag
        if token[:type] == :EmptyTag
          save = @tokenizer.content_model_flag
          @phase.processStartTag(token[:name], token[:data])
          @tokenizer.content_model_flag = save
          token[:data] = {}
          token[:type] = :EndTag
        end

      when :Characters
        # un-escape RCDATA_ELEMENTS (e.g. style, script)
        if @tokenizer.content_model_flag == :CDATA
          token[:data] = token[:data].
            gsub('&lt;','<').gsub('&gt;','>').gsub('&amp;','&')
        end

      when :EndTag
        if token[:data]
           parse_error("attributes-in-end-tag")
        end

      when :Comment
        # Rescue CDATA from the comments
        if token[:data][0..6] == "[CDATA[" and token[:data][-2..-1] == "]]"
          token[:type] = :Characters
          token[:data] = token[:data][7 ... -2]
        end
      end

      return token
    end