<commit_before>require 'libxml'
require 'cgi'

module ROXML
  module XML # :nodoc:all
    Document = LibXML::XML::Document
    Node = LibXML::XML::Node
    Parser = LibXML::XML::Parser
    Error = LibXML::XML::Error

    module NamespacedSearch
      def search(xpath)
        if namespaces.default && !xpath.include?(':')
          find(namespaced(xpath),
               in_default_namespace(namespaces.default.href))
        else
          find(xpath)
        end
      end

    private
      def namespaced(xpath)
        xpath.split('/').map do |component|
          if component =~ /\w+/ && !component.include?(':') && !component.starts_with?('@')
            in_default_namespace(component)
          else
            component
          end
        end.join('/')
      end

      def in_default_namespace(name)
        "roxmldefaultnamespace:#{name}"
      end
    end

    class Document
      include NamespacedSearch

    private
      delegate :namespaces, :to => :root
    end

    class Node
      include NamespacedSearch

      class << self
        def new_with_entity_escaping(name, content = nil, namespace = nil)
          new_without_entity_escaping(name, content && CGI.escapeHTML(content), namespace)
        end
        alias_method_chain :new, :entity_escaping

        alias :create :new
      end

      def default_namespace
        doc.namespaces.default.try(:prefix)
      end

      def add_child(child)
        # libxml 1.1.3 changed child_add from returning child to returning self
        self << child
        child
      end

      alias_method :set_libxml_content, :content=
      def content=(string)
        set_libxml_content(string.gsub('&', '&amp;'))
      end
    end<commit_msg>Update libxml to the latest namespace treatment<commit_after>require 'libxml'
require 'cgi'

module ROXML
  module XML # :nodoc:all
    Document = LibXML::XML::Document
    Node = LibXML::XML::Node
    Parser = LibXML::XML::Parser
    Error = LibXML::XML::Error

    module NamespacedSearch
      def search(xpath)
        if namespaces.default
          find(xpath, in_default_namespace(namespaces.default.href))
        else
          find(xpath)
        end
      end

    private
      def namespaced(xpath)
        xpath.split('/').map do |component|
          if component =~ /\w+/ && !component.include?(':') && !component.starts_with?('@')
            in_default_namespace(component)
          else
            component
          end
        end.join('/')
      end

      def in_default_namespace(name)
        "xmlns:#{name}"
      end
    end

    class Document
      include NamespacedSearch

    private
      delegate :namespaces, :to => :root
    end

    class Node
      include NamespacedSearch

      class << self
        def new_with_entity_escaping(name, content = nil, namespace = nil)
          new_without_entity_escaping(name, content && CGI.escapeHTML(content), namespace)
        end
        alias_method_chain :new, :entity_escaping

        alias :create :new
      end

      def default_namespace
        default = doc.namespaces.default
        default.prefix || 'xmlns' if default
      end

      def add_child(child)
        # libxml 1.1.3 changed child_add from returning child to returning self
        self << child
        child
      end

      alias_method :set_libxml_content, :content=
      def content=(string)
        set_libxml_content(string.gsub('&', '&amp;'))
      end
    end
{'fraction_non_alphanumeric': 0.09446537235583889, 'fraction_numerical': 0.0017386264850767893, 'mean_word_length': 2.1845018450184504, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5693690', 'n_tokens_mistral': 1024, 'n_tokens_neox': 977, 'n_words': 239}