@@ -20,10 +20,11 @@ namespace :secure_headers do
20
20
( is_erb? ( filename ) && inline_script =~ /<%.*%>/ )
21
21
end
22
22
23
- def find_inline_content ( filename , regex , hashes )
23
+ def find_inline_content ( filename , regex , hashes , strip_trailing_whitespace )
24
24
file = File . read ( filename )
25
25
file . scan ( regex ) do # TODO don't use gsub
26
26
inline_script = Regexp . last_match . captures . last
27
+ inline_script . gsub! ( /(\r ?\n )[\t ]+\z / , '\1' ) if strip_trailing_whitespace
27
28
if dynamic_content? ( filename , inline_script )
28
29
puts "Looks like there's some dynamic content inside of a tag :-/"
29
30
puts "That pretty much means the hash value will never match."
@@ -38,19 +39,17 @@ namespace :secure_headers do
38
39
def generate_inline_script_hashes ( filename )
39
40
hashes = [ ]
40
41
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 )
44
44
45
45
hashes
46
46
end
47
47
48
48
def generate_inline_style_hashes ( filename )
49
49
hashes = [ ]
50
50
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 )
54
53
55
54
hashes
56
55
end
0 commit comments