Sha256: a7e8bbe73555a8b73ece9fe70b128efc83aabd8bdf94e9e8bad4c0f39b08158e

Contents?: true

Size: 758 Bytes

Versions: 3

Compression:

Stored size: 758 Bytes

Contents

# frozen_string_literal: true

module Capybara
  class Selector
    class CSS
      def self.escape(str)
        value = str.dup
        out = +""
        out << value.slice!(0...1) if value =~ /^[-_]/
        out << (value[0] =~ NMSTART ? value.slice!(0...1) : escape_char(value.slice!(0...1)))
        out << value.gsub(/[^a-zA-Z0-9_-]/) { |c| escape_char c }
        out
      end

      def self.escape_char(c)
        c =~ %r{[ -/:-~]} ? "\\#{c}" : format("\\%06x", c.ord)
      end

      S = '\u{80}-\u{D7FF}\u{E000}-\u{FFFD}\u{10000}-\u{10FFFF}'
      H = /[0-9a-fA-F]/
      UNICODE  = /\\#{H}{1,6}[ \t\r\n\f]?/
      NONASCII = /[#{S}]/
      ESCAPE   = /#{UNICODE}|\\[ -~#{S}]/
      NMSTART  = /[_a-zA-Z]|#{NONASCII}|#{ESCAPE}/
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
tdiary-5.0.9 vendor/bundle/gems/capybara-3.2.1/lib/capybara/selector/css.rb
capybara-3.2.1 lib/capybara/selector/css.rb
capybara-3.2.0 lib/capybara/selector/css.rb