Sha256: 7246dd5a08d16a5a57531009b4af94217ca23c67ffd347813538a8cc0cadd68a

Contents?: true

Size: 909 Bytes

Versions: 14

Compression:

Stored size: 909 Bytes

Contents

module Nanoc::Extra::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::Extra::Checking::Check
    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].downcase == 'http'
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
nanoc-4.1.1 lib/nanoc/extra/checking/checks/mixed_content.rb
nanoc-4.1.0 lib/nanoc/extra/checking/checks/mixed_content.rb
nanoc-4.1.0rc2 lib/nanoc/extra/checking/checks/mixed_content.rb
nanoc-4.1.0rc1 lib/nanoc/extra/checking/checks/mixed_content.rb
nanoc-4.1.0b1 lib/nanoc/extra/checking/checks/mixed_content.rb
nanoc-4.1.0a1 lib/nanoc/extra/checking/checks/mixed_content.rb
nanoc-4.0.2 lib/nanoc/extra/checking/checks/mixed_content.rb
nanoc-4.0.1 lib/nanoc/extra/checking/checks/mixed_content.rb
nanoc-4.0.0 lib/nanoc/extra/checking/checks/mixed_content.rb
nanoc-4.0.0rc3 lib/nanoc/extra/checking/checks/mixed_content.rb
nanoc-4.0.0rc2 lib/nanoc/extra/checking/checks/mixed_content.rb
nanoc-4.0.0rc1 lib/nanoc/extra/checking/checks/mixed_content.rb
nanoc-4.0.0b4 lib/nanoc/extra/checking/checks/mixed_content.rb
nanoc-4.0.0b3 lib/nanoc/extra/checking/checks/mixed_content.rb