jrb 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/jrb/rails.rb +4 -1
- data/lib/jrb/version.rb +1 -1
- data/test/action_view_test.rb +11 -1
- data/test/dummy/app/views/test/index.json.rb +1 -0
- data/test/dummy/app/views/test/index.xml.rb +5 -0
- metadata +6 -2
data/lib/jrb/rails.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
module JRB
|
2
2
|
module Rails
|
3
3
|
class TemplateHandler
|
4
|
+
HTML_MIME_TYPES = ["text/html", "application/xhtml+xml"]
|
5
|
+
|
4
6
|
class << self
|
5
7
|
def call(template)
|
6
|
-
|
8
|
+
auto_escape = HTML_MIME_TYPES.include? template.mime_type
|
9
|
+
tilt_template = JRB::Template.new(template.identifier, 1, :escape_html => auto_escape) { template.source }
|
7
10
|
tilt_template.send(:precompiled, {}).first
|
8
11
|
end
|
9
12
|
end
|
data/lib/jrb/version.rb
CHANGED
data/test/action_view_test.rb
CHANGED
@@ -9,10 +9,20 @@ class ActionViewTest < ActionController::TestCase
|
|
9
9
|
assert_equal "<html><head></head><body>Hello John!</body></html>", response.body
|
10
10
|
end
|
11
11
|
|
12
|
-
test "escaping html characters" do
|
12
|
+
test "escaping html characters in html templates" do
|
13
13
|
get :index, :name => "<script>unsafe</script>"
|
14
14
|
assert_equal "<html><head></head><body>Hello <script>unsafe</script>!</body></html>", response.body
|
15
15
|
end
|
16
|
+
|
17
|
+
test "not escaping html characters in xml templates" do
|
18
|
+
get :index, :name => "<script>unsafe</script>", :format => :xml
|
19
|
+
assert_equal "<greeting>Hello <script>unsafe</script>!</greeting>", response.body
|
20
|
+
end
|
21
|
+
|
22
|
+
test "not escaping html characters in json templates" do
|
23
|
+
get :index, :name => "<script>safe</script>", :format => :json
|
24
|
+
assert_equal '{"greeting":"Hello <script>safe</script>!"}', response.body
|
25
|
+
end
|
16
26
|
|
17
27
|
test "capturing content" do
|
18
28
|
get :capture, :name => "John"
|
@@ -0,0 +1 @@
|
|
1
|
+
{ :greeting => "Hello #{params[:name]}!" }.to_json
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: jrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Rolf Timmermans
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-06-07 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: tilt
|
@@ -61,6 +61,8 @@ files:
|
|
61
61
|
- test/dummy/app/views/layouts/test.html.rb
|
62
62
|
- test/dummy/app/views/test/capture.html.rb
|
63
63
|
- test/dummy/app/views/test/index.html.rb
|
64
|
+
- test/dummy/app/views/test/index.json.rb
|
65
|
+
- test/dummy/app/views/test/index.xml.rb
|
64
66
|
- test/dummy/config.ru
|
65
67
|
- test/dummy/config/application.rb
|
66
68
|
- test/dummy/config/boot.rb
|
@@ -102,6 +104,8 @@ test_files:
|
|
102
104
|
- test/dummy/app/views/layouts/test.html.rb
|
103
105
|
- test/dummy/app/views/test/capture.html.rb
|
104
106
|
- test/dummy/app/views/test/index.html.rb
|
107
|
+
- test/dummy/app/views/test/index.json.rb
|
108
|
+
- test/dummy/app/views/test/index.xml.rb
|
105
109
|
- test/dummy/config.ru
|
106
110
|
- test/dummy/config/application.rb
|
107
111
|
- test/dummy/config/boot.rb
|