Sha256: f7b766249a7de1c7d7a557ca0dc9d868f8db4d93e9b97b70f400f424678a3a6d

Contents?: true

Size: 936 Bytes

Versions: 9

Compression:

Stored size: 936 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_html_filenames
      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

9 entries across 9 versions & 1 rubygems

Version Path
nanoc-4.10.3 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.10.2 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.10.1 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.10.0 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.9.9 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.9.8 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.9.7 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.9.6 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.9.5 lib/nanoc/checking/checks/mixed_content.rb