unobtrusive_flash 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWU1ZTA0MjUzNzMyYmY4MTkzZGUzMzE3MmEzNmE1NTc2YWEwYTA4NQ==
4
+ YTFiNGZlYTIwNDBjMDEwZTVmMGM3Mzc4YTExZDEyNTJlZmNlYjNlNw==
5
5
  data.tar.gz: !binary |-
6
- OTVhNmFkNWI2YTFjYjk3MjY2YjI5YjI2Yjg5MDY1YjQzNzc3YTM2NQ==
7
- !binary "U0hBNTEy":
6
+ NGE5MWVkZWVhODFlZGNmYWM1YzRhZWZkNDczYWQ3YWFlY2FkYmEzYw==
7
+ SHA512:
8
8
  metadata.gz: !binary |-
9
- MDkwODU2YmEzNTJjODJmYTg2MDhhZDllMzUwYmRiYjdiNjNlNTY0MDcyMjdi
10
- NDkzYTk4MjVmYjk5N2RhMjEyN2NhYTBkZjg2ODU2NDZhYmMzNTJkNDNhNjkz
11
- NzI3NGIxODQwMmI1NTU3MjUzYjRkNGQzOGJkODA3MTNmMTcwY2M=
9
+ YzExMDQ1YjM2ODA3YjFmOGZlZWM5MWY3MjViYmYzYmRmMjc3Y2NhYjc2NGUw
10
+ ZTJlOWJlZjdjNzllMTdmOTYxMWI5OWI5YWY5ZGQ3MDRkMmVkNmNkNDg1NTdh
11
+ NTUwNmM1YTRjNWM5Y2FjNzJiOTg5YjQ2YmYwNDc4Mzk0OGJmNjE=
12
12
  data.tar.gz: !binary |-
13
- YjIxMGFkMjkzZjMyYjg0ZWQ5NWQ1OWU1YmJkZTk3ZDk3MTVmZTgxZjY1NTI5
14
- N2M5ZGVlNTlhYjA5ODY1OGIxM2ZhOTZjYjYwNGJiZjQxOTgwYmE0NWVmNTEx
15
- OWUyZjE0MGMwMjE5Yjk2NzM1MDNkMjk3NDcwYmM0Mjg3YzZiMjc=
13
+ MzU3YTc0NDI5OGI2NjY2MjEzZjI3NmNmODlmYmE4OWRmNTRjNmE5MTY5OTk4
14
+ Nzc1NDI3OWUwNzk1YjMzNWY0Njg5YmU3OWYyN2VlNDNkM2FlMzhkMWZkYjEz
15
+ NjY2NWZkOTZlMTFjNzI2NTI1NTRhYWY4MTA3NTQzMmU0OWY0NDk=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2013-12-21 2.1.0
2
+
3
+ * Changed message escaping logic to use the Rails html_safe conventions (Possibly breaking change)
4
+
1
5
  ## 2013-10-09 2.0.0
2
6
 
3
7
  * Grand refactoring
data/README.markdown CHANGED
@@ -30,12 +30,15 @@ Tested in:
30
30
 
31
31
  ## Usage
32
32
 
33
- 1. Add the gem to your Rails app.
33
+ 1. Add the `unobtrusive_flash` gem to your Gemfile.
34
+
35
+ gem 'unobtrusive_flash', '~>2'
36
+
34
37
  2. Add the following to the controllers that generate flash messages (or better, to the `ApplicationController`):
35
38
 
36
39
  after_filter :prepare_unobtrusive_flash
37
40
 
38
- Important! **Flash messages are NOT HTML escaped**, so you can use any markup in them. Take additional care to protect yourself from injection attacks if necessary.
41
+ Flash messages are HTML escaped in the same manner as regular Rails view code: if a message is not `html_safe`, it is escaped, otherwise not. This lets you use helpers such as `link_to` in your messages.
39
42
 
40
43
  3. Include `require unobtrusive_flash` in your `application.js`.
41
44
 
@@ -1,3 +1,5 @@
1
+ require 'active_support/core_ext/string/output_safety'
2
+
1
3
  module UnobtrusiveFlash
2
4
  module ControllerMixin
3
5
  protected
@@ -10,10 +12,19 @@ module UnobtrusiveFlash
10
12
  cookie_flash=[] unless cookie_flash.is_a? Array
11
13
  end
12
14
 
13
- cookie_flash += flash.to_a
15
+ cookie_flash += UnobtrusiveFlash::ControllerMixin.sanitize_flash(flash)
14
16
  cookies[:flash] = {:value => cookie_flash.to_json, :domain => :all}
15
17
  flash.discard
16
18
  end
17
19
  end
20
+
21
+ class << self
22
+ def sanitize_flash(flash)
23
+ flash.to_a.map do |key, value|
24
+ html_safe_value = value.html_safe? ? value : ERB::Util.html_escape(value)
25
+ [key, html_safe_value]
26
+ end
27
+ end
28
+ end
18
29
  end
19
30
  end
@@ -1,3 +1,3 @@
1
1
  module UnobtrusiveFlash
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe UnobtrusiveFlash::ControllerMixin do
4
+ describe '.sanitize_flash' do
5
+ it 'should escape messages that are not html safe' do
6
+ described_class.sanitize_flash({:foo => '<bar>'}).should == [[:foo, '&lt;bar&gt;']]
7
+ end
8
+
9
+ it 'should not escape messages that are html safe' do
10
+ described_class.sanitize_flash({:foo => '<bar>'.html_safe}).should == [[:foo, '<bar>']]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ require 'bundler'
2
+ require 'rspec'
3
+ require 'unobtrusive_flash'
@@ -25,4 +25,5 @@ EOT
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.3"
27
27
  spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec"
28
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unobtrusive_flash
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonid Shevtsov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-09 00:00:00.000000000 Z
11
+ date: 2013-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: ! 'unobtrusive_flash takes your flash messages for the backend and automagically
56
70
  passes them to the frontend via HTTP cookies.
57
71
 
@@ -72,15 +86,17 @@ files:
72
86
  - Gemfile
73
87
  - README.markdown
74
88
  - Rakefile
89
+ - lib/assets/javascripts/unobtrusive_flash.js
90
+ - lib/assets/javascripts/unobtrusive_flash_bootstrap.js
91
+ - lib/assets/javascripts/unobtrusive_flash_ui.js
92
+ - lib/assets/stylesheets/unobtrusive_flash_ui.css
75
93
  - lib/unobtrusive_flash.rb
76
94
  - lib/unobtrusive_flash/controller_mixin.rb
77
95
  - lib/unobtrusive_flash/engine.rb
78
96
  - lib/unobtrusive_flash/version.rb
97
+ - spec/sanitize_flash_spec.rb
98
+ - spec/spec_helper.rb
79
99
  - unobtrusive_flash.gemspec
80
- - vendor/assets/javascripts/unobtrusive_flash.js
81
- - vendor/assets/javascripts/unobtrusive_flash_bootstrap.js
82
- - vendor/assets/javascripts/unobtrusive_flash_ui.js
83
- - vendor/assets/stylesheets/unobtrusive_flash_ui.css
84
100
  homepage: https://github.com/leonid-shevtsov/unobtrusive_flash
85
101
  licenses: []
86
102
  metadata: {}
@@ -100,8 +116,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
116
  version: '0'
101
117
  requirements: []
102
118
  rubyforge_project:
103
- rubygems_version: 2.0.5
119
+ rubygems_version: 2.1.11
104
120
  signing_key:
105
121
  specification_version: 4
106
122
  summary: Unobtrusive flash messages for Rails
107
- test_files: []
123
+ test_files:
124
+ - spec/sanitize_flash_spec.rb
125
+ - spec/spec_helper.rb