asset_bom_removal-rails 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f59301107c46145d4c017052fe4d35ddf67e91db
4
+ data.tar.gz: 185fba902717de245bdd7ab9399a70b92fe85984
5
+ SHA512:
6
+ metadata.gz: 7becb82d56a30be368f6d4ca288e4ae012484d715607a05edb8acdb7f17013f9d05d0dec4950c55b56920e668b6bc6cd2302a82876fb1259bc0e62692d197f0f
7
+ data.tar.gz: 2682457fadeac5509561b443a469b18eedce056ad22683ebcb2c59acbbed8d15e192bf17b66532b76941e3637b3cbfc1f6d545f9a0e14bd29619c1b63b4a1fbd
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ 2.4
File without changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in asset-bom-removal-rails.gemspec
4
+ gemspec
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env groovy
2
+
3
+ node {
4
+ def govuk = load '/var/lib/jenkins/groovy_scripts/govuk_jenkinslib.groovy'
5
+ govuk.buildProject()
6
+ }
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Crown Copyright (Government Digital Service)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # Asset::Bom::Removal::Rails
2
+
3
+ This gem hooks into [Rails `assets:precompile` task](http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets) and removes the BOM from any CSS files (and their gzipped versions) in the asset root.
4
+
5
+ We do this because we want to use [SRI](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) on our assets, but [a bug in Firefox versions < 52](https://bugzilla.mozilla.org/show_bug.cgi?id=1269241) means it calculates the hash incorrectly when the CSS asset has a [BOM](https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8) and refuses to load the asset. The BOM is [generated by SASS versions > 3.4](https://github.com/sass/sass/blob/3.4.0/lib/sass/tree/visitors/to_css.rb#L131-L140) and in the versions of rails, sass, sprockets, sass-rails, and sprockets-rails we use it is impossible to configure SASS to stop doing this (as mentioned [in the sass-rails readme](https://github.com/rails/sass-rails/blob/v4.0.0/README.md#configuration) from version 4.0+).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'asset-bom-removal-rails'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install asset_bom_removal-rails
22
+
23
+ ## Usage
24
+
25
+ The gem hooks itself into rails assets pipeline so when you run `assets:precompile` it will be used. When a css file is compiled with this gem in the app any BOM added by sass will be removed before the compiled CSS is passed to the rest of the asset pipeline to be persisted and added to the manifest.
26
+
27
+ It should only affect production environments because sass is (by default) only configured to use `:compressed` style (and thus generate BOMs) in production mode. In development it uses `:expanded` which does not trigger the BOM insertion.
28
+
29
+ It replaces the default `css_compressor` (as configured in rails via `config.assets.css_compressor`) with a version that strips the BOM. It won't do it if the `css_compressor` is configured and is not `:sass` or `:scss`.
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests.
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/alphagov/asset-bom-removal-rails.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
42
+
@@ -0,0 +1,6 @@
1
+ require "rspec/core/rake_task"
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task test: :spec
6
+ task default: :spec
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'asset_bom_removal/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "asset_bom_removal-rails"
8
+ spec.version = AssetBomRemoval::Rails::VERSION
9
+ spec.authors = ["Government Digital Service"]
10
+ spec.email = ["govuk-dev@digital.cabinet-office.gov.uk"]
11
+
12
+ spec.summary = "Removes the BOM from CSS files in rails asset pipeline"
13
+ spec.description = "Hooks into rails asset:precompile task to remove the BOM from any CSS files generated by SASS. Firefox < 52 has a bug when calculating SRI for CSS files with a BOM and removing it has no downsides so that's what we do."
14
+ spec.homepage = "https://github.com/alphagov/asset_bom_removal-rails"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "rails", ">= 4.2"
23
+ spec.add_dependency "sass", "> 3.4"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.14"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "govuk-lint"
29
+ end
@@ -0,0 +1 @@
1
+ require "asset_bom_removal/rails/railtie" if defined?(Rails)
@@ -0,0 +1,32 @@
1
+ require 'asset_bom_removal/sass_no_bom_compressor'
2
+
3
+ module AssetBomRemoval
4
+ module Rails
5
+ class Railtie < ::Rails::Railtie
6
+ def sass_might_output_bom?(app)
7
+ ::Rails.env.production? || app.config.sass.style == :compressed
8
+ end
9
+
10
+ def app_uses_sass_for_css_compression?(app)
11
+ # if css_compressor is not already set, it will be set to sass by
12
+ # sass-rails
13
+ css_compressor = (app.config.assets.fetch(:css_compressor, nil) || :sass)
14
+ [:sass, :scss].include? css_compressor.to_sym
15
+ end
16
+
17
+ def setup_css_compression_with_bom_removal(app)
18
+ if sass_might_output_bom?(app)
19
+ # We only need to do this if sass will be using :compressed style
20
+ # because other styles don't output a BOM
21
+ if app_uses_sass_for_css_compression?(app)
22
+ app.config.assets.css_compressor = AssetBomRemoval::SassNoBomCompressor
23
+ end
24
+ end
25
+ end
26
+
27
+ initializer :setup_css_compression_with_bom_removal, group: :all do |app|
28
+ setup_css_compression_with_bom_removal(app)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ module AssetBomRemoval
2
+ module Rails
3
+ VERSION = '0.0.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ require 'sprockets/sass_compressor'
2
+
3
+ module AssetBomRemoval
4
+ class SassNoBomCompressor < Sprockets::SassCompressor
5
+ # Let the default sass processor do all the hard work
6
+ def call(input)
7
+ remove_bom_from_css(super(input))
8
+ end
9
+
10
+ private
11
+
12
+ def remove_bom_from_css(css_string)
13
+ if css_string.bytes[0..2] == [0xEF, 0xBB, 0xBF]
14
+ css_string[3..-1]
15
+ else
16
+ css_string
17
+ end
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asset_bom_removal-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Government Digital Service
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sass
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: govuk-lint
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Hooks into rails asset:precompile task to remove the BOM from any CSS
98
+ files generated by SASS. Firefox < 52 has a bug when calculating SRI for CSS files
99
+ with a BOM and removing it has no downsides so that's what we do.
100
+ email:
101
+ - govuk-dev@digital.cabinet-office.gov.uk
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".ruby-version"
109
+ - CHANGELOG.md
110
+ - Gemfile
111
+ - Jenkinsfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - asset_bom_removal-rails.gemspec
116
+ - lib/asset_bom_removal/rails.rb
117
+ - lib/asset_bom_removal/rails/railtie.rb
118
+ - lib/asset_bom_removal/rails/version.rb
119
+ - lib/asset_bom_removal/sass_no_bom_compressor.rb
120
+ homepage: https://github.com/alphagov/asset_bom_removal-rails
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.6.8
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Removes the BOM from CSS files in rails asset pipeline
144
+ test_files: []