@@ -20,10 +20,11 @@ namespace :secure_headers do
2020 ( is_erb? ( filename ) && inline_script =~ /<%.*%>/ )
2121 end
2222
23- def find_inline_content ( filename , regex , hashes )
23+ def find_inline_content ( filename , regex , hashes , strip_trailing_whitespace )
2424 file = File . read ( filename )
2525 file . scan ( regex ) do # TODO don't use gsub
2626 inline_script = Regexp . last_match . captures . last
27+ inline_script . gsub! ( /(\r ?\n )[\t ]+\z / , '\1' ) if strip_trailing_whitespace
2728 if dynamic_content? ( filename , inline_script )
2829 puts "Looks like there's some dynamic content inside of a tag :-/"
2930 puts "That pretty much means the hash value will never match."
@@ -38,19 +39,17 @@ namespace :secure_headers do
3839 def generate_inline_script_hashes ( filename )
3940 hashes = [ ]
4041
41- [ INLINE_SCRIPT_REGEX , INLINE_HASH_SCRIPT_HELPER_REGEX ] . each do |regex |
42- find_inline_content ( filename , regex , hashes )
43- end
42+ find_inline_content ( filename , INLINE_SCRIPT_REGEX , hashes , false )
43+ find_inline_content ( filename , INLINE_HASH_SCRIPT_HELPER_REGEX , hashes , true )
4444
4545 hashes
4646 end
4747
4848 def generate_inline_style_hashes ( filename )
4949 hashes = [ ]
5050
51- [ INLINE_STYLE_REGEX , INLINE_HASH_STYLE_HELPER_REGEX ] . each do |regex |
52- find_inline_content ( filename , regex , hashes )
53- end
51+ find_inline_content ( filename , INLINE_STYLE_REGEX , hashes , false )
52+ find_inline_content ( filename , INLINE_HASH_STYLE_HELPER_REGEX , hashes , true )
5453
5554 hashes
5655 end
0 commit comments