Sha256: 99ccc8d97a70d7dcee5412e6a42e0a4d5b45625d24f101803b9082d7f2a2b6aa

Contents?: true

Size: 972 Bytes

Versions: 27

Compression:

Stored size: 972 Bytes

Contents

# frozen_string_literal: true

module Nanoc::Checking::Checks
  # A check that verifies HTML files do not reference external resources with
  # URLs that would trigger "mixed content" warnings.
  #
  # @api private
  class MixedContent < ::Nanoc::Checking::Check
    identifier :mixed_content

    PROTOCOL_PATTERN = /^(\w+):\/\//

    def run
      filenames = output_filenames.select { |f| File.extname(f) == '.html' }
      resource_uris_with_filenames = ::Nanoc::Extra::LinkCollector.new(filenames).filenames_per_resource_uri

      resource_uris_with_filenames.each_pair do |uri, fns|
        next unless guaranteed_insecure?(uri)
        fns.each do |filename|
          add_issue(
            "mixed content include: #{uri}",
            subject: filename,
          )
        end
      end
    end

    private

    def guaranteed_insecure?(href)
      protocol = PROTOCOL_PATTERN.match(href)

      protocol && protocol[1].casecmp('http').zero?
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
nanoc-4.9.1 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.9.0 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.19 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.18 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.17 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.16 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.15 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.14 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.13 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.12 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.11 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.10 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.9 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.8 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.7 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.6 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.5 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.4 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.3 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.8.2 lib/nanoc/checking/checks/mixed_content.rb