\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7<F<2PFAFZUP_xxnnx\F5\AF\B9\91\C8\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\DB\00CUZZxix‚\EB\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\C0\00\00b\00d\00\FF\C4\00\00\00\00\00\00\00\00\00\00\00\00\00\00\FF\C4\00\00\00\00\00\00\00\00\00\00\001A!Q\FF\C4\00\00\00\00\00\00\00\00\00\00\00\00\00\FF\C4\00\00\00\00\00\00\00\00\00\00!1AQ\FF\DA\00\00\00?\00\F6\00\00\00\00\00\00\00\00\00\00\A0\00\00\C5\CF\F8\E7Ó\FCjD~\B9^\AD\%\B3]\D8cs-\BBs,-\A0\00"\80\00%\B83rÏ^K~F\A4ea\00E\00\C6\EE=u\B1\9B\D1\00@\00r\BE8\F9:\FE5#.M\00\E7\CB\C9q\CBq\D6\F2\BE\B7\C7>\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7	\8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh
\00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€
\00$\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95
59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>C///</title>
</head>
require "helper"

require 'nkf'

module Nokogiri
  module HTML
    class TestNode < Nokogiri::TestCase
      def setup
        super
        @html = Nokogiri::HTML(<<-eohtml)
        <html>
          <head></head>
          <body>
            <div class='baz'><a href="foo" class="bar">first</a></div>
          </body>
        </html>
        eohtml
      end

      def test_to_a
        assert_equal [['class', 'bar'], ['href', 'foo']],@html.at('a').to_a.sort
      end

      def test_attr
        node = @html.at('div.baz')
        assert_equal node['class'], node.attr('class')
      end

      def test_get_attribute
        element = @html.at('div')
        assert_equal 'baz', element.get_attribute('class')
        assert_equal 'baz', element['class']
        element['href'] = "javascript:alert(\"AGGA-KA-BOO!\")"
        assert_match(/%22AGGA-KA-BOO!%22/, element.to_html)
      end

      # The HTML parser ignores namespaces, so even properly declared namespaces
      # are treated as as undeclared and have to be accessed via prefix:tagname
      def test_ns_attribute
        html = '<i foo:bar="baz"></i>'
        doc = Nokogiri::HTML(html)
        assert_equal 'baz', (doc%'i')['foo:bar']
      end

      def test_css_path_round_trip
        doc = Nokogiri::HTML(File.read(HTML_FILE))
        %w{ #header small div[2] div.post body }.each do |css_sel|
          ele = doc.at css_sel
          assert_equal ele, doc.at(ele.css_path), ele.css_path
        end
      end

      def test_path_round_trip
        doc = Nokogiri::HTML(File.read(HTML_FILE))
        %w{ #header small div[2] div.post body }.each do |css_sel|
          ele = doc.at css_sel
          assert_equal ele, doc.at(ele.path), ele.path
        end
      end

      def test_append_with_document
        assert_raises(ArgumentError) do
          @html.root << Nokogiri::HTML::Document.new
        end
      end

      ###
      # Make sure a document that doesn't declare a meta encoding returns
      # nil.
      def test_meta_encoding
        assert_nil @html.meta_encoding
      end

      def test_description
        assert desc = @html.at('a.bar').description
        assert_equal 'a', desc.name
      end

      def test_ancestors_with_selector
        assert node = @html.at('a.bar').child
        assert list = node.ancestors('.baz')
        assert_equal 1, list.length
        assert_equal 'div', list.first.name
      end

      def test_matches_inside_fragment
        fragment = DocumentFragment.new @html
        fragment << XML::Node.new('a', @html)

        a = fragment.children.last
        assert a.matches?('a'), 'a should match'
      end

      def test_css_matches?
        assert node = @html.at('a.bar')
        assert node.matches?('a.bar')
      end

      def test_xpath_matches?
        assert node = @html.at('//a')
        assert node.matches?('//a')
      end

      def test_unlink_then_swap
        node = @html.at('a')
        node.unlink

        another_node = @html.at('div')
        assert another_node, 'should have a node'

        # This used to segv
        assert node.add_previous_sibling another_node
      end

      def test_swap
        @html.at('div').swap('<a href="foo">bar</a>')
        a_tag = @html.css('a').first
        assert_equal 'body', a_tag.parent.name
        assert_equal 0, @html.css('div').length
      end

      def test_swap_with_regex_characters
        @html.at('div').swap('<a href="foo">ba)r</a>')
        a_tag = @html.css('a').first
        assert_equal 'ba)r', a_tag.text
      end

      def test_attribute_decodes_entities
        node = @html.at('div')
        node['href'] = 'foo&bar'
        assert_equal 'foo&bar', node['href']
        node['href'] += '&baz'
        assert_equal 'foo&bar&baz', node['href']
      end

      def test_parse_config_option
        node = @html.at('div')
        options = nil
        node.parse("<div></div>") do |config|
          options = config
        end
        assert_equal Nokogiri::XML::ParseOptions::DEFAULT_HTML, options.to_i
      end

      def test_fragment_handler_does_not_regurge_on_invalid_attributes
        iframe = %Q{<iframe style="width: 0%; height: 0px" src="http://someurl" allowtransparency></iframe>}
        assert @html.at('div').fragment(iframe)
      end

      def test_fragment
        fragment = @html.fragment(<<-eohtml)
          hello
          <div class="foo">
            <p>bar</p>
          </div>
          world
        eohtml
        assert_match(/^hello/, fragment.inner_html.strip)
        assert_equal 3, fragment.children.length
        assert p_tag = fragment.css('p').first
        assert_equal 'div', p_tag.parent.name
        assert_equal 'foo', p_tag.parent['class']
      end

      def test_fragment_serialization
    