Sha256: 38d52ffed5f1bbb7c2514a49cac7a8172da0143df480c4e428521401274e899d

Contents?: true

Size: 941 Bytes

Versions: 20

Compression:

Stored size: 941 Bytes

Contents

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

20 entries across 20 versions & 1 rubygems

Version Path
nanoc-4.7.9 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.7.8 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.7.7 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.7.6 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.7.5 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.7.4 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.7.3 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.7.2 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.7.1 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.7.0 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.6.4 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.6.3 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.6.2 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.6.1 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.6.0 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.5.4 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.5.3 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.5.2 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.5.1 lib/nanoc/checking/checks/mixed_content.rb
nanoc-4.5.0 lib/nanoc/checking/checks/mixed_content.rb