sinatra-jsonp 0.3.2 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2010 by Serg Podtynnyi
1
+ Copyright (C) 2012 by Serg Podtynnyi
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Sinatra::Jsonp ![Project status](http://stillmaintained.com/shtirlic/sinatra-jsonp.png)
1
+ Sinatra::Jsonp [![Build Status](https://travis-ci.org/shtirlic/sinatra-jsonp.png)](https://travis-ci.org/shtirlic/sinatra-jsonp)
2
2
  ==============
3
3
 
4
4
  JSONP output helper for [Sinatra](http://sinatrarb.com). Automatically detects callback params and returns proper JSONP output.
data/lib/sinatra/jsonp.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  require 'sinatra/base'
2
- require 'json'
2
+ require 'multi_json'
3
3
 
4
4
  module Sinatra
5
5
  module Jsonp
6
6
  def jsonp(*args)
7
7
  if args.size > 0
8
- data = args[0].to_json
8
+ data = MultiJson.dump args[0]
9
9
  if args.size > 1
10
10
  callback = args[1].to_s
11
11
  else
@@ -14,6 +14,7 @@ module Sinatra
14
14
  end
15
15
  end
16
16
  if callback
17
+ callback.tr!('^a-zA-Z0-9_$\.', '')
17
18
  content_type :js
18
19
  response = "#{callback}(#{data})"
19
20
  else
data/spec/jsonp_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'backports'
2
- require_relative 'spec_helper'
2
+ require 'spec_helper'
3
3
 
4
4
  describe Sinatra::Jsonp do
5
5
  before do
@@ -17,19 +17,25 @@ describe Sinatra::Jsonp do
17
17
  end
18
18
  end
19
19
 
20
- it "should return JSON if no callback passed" do
20
+ it "returns JSON if no callback passed" do
21
21
  get '/method'
22
22
  body.should == '["hello","hi","hallo"]'
23
23
  end
24
- it "should return JSONP if callback passed via GET param" do
24
+ it "returns JSONP if callback passed via request params" do
25
25
  get '/method?callback=functionA'
26
26
  body.should == 'functionA(["hello","hi","hallo"])'
27
27
  end
28
- it "should return JSONP if callback passed via method param" do
28
+
29
+ it "returns JSONP with sanitized callback" do
30
+ get '/method', { :callback=>'foo<script>alert(1)</script>' }
31
+ body.should == 'fooscriptalert1script(["hello","hi","hallo"])'
32
+ end
33
+
34
+ it "returns JSONP if callback passed via method param" do
29
35
  get '/method_with_params'
30
36
  body.should == 'functionA(["hello","hi","hallo"])'
31
37
  end
32
- it "should return JSONP with callback passed via method params even if it passed via GET param" do
38
+ it "returns JSONP with callback passed via method params even if it passed via request param" do
33
39
  get '/method_with_params?callback=functionB'
34
40
  body.should == 'functionA(["hello","hi","hallo"])'
35
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-jsonp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: '0.4'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-16 00:00:00.000000000 Z
12
+ date: 2012-11-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &82328930 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,21 +21,31 @@ dependencies:
21
21
  version: '1.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *82328930
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
25
30
  - !ruby/object:Gem::Dependency
26
- name: json_pure
27
- requirement: &82328400 !ruby/object:Gem::Requirement
31
+ name: multi_json
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
31
36
  - !ruby/object:Gem::Version
32
- version: '1.4'
37
+ version: 1.3.7
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *82328400
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.3.7
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rspec
38
- requirement: &82327530 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '2.3'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *82327530
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.3'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rake
49
- requirement: &83330550 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *83330550
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: sinatra-contrib
60
- requirement: &83330280 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ~>
@@ -65,16 +85,21 @@ dependencies:
65
85
  version: '1.0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *83330280
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '1.0'
69
94
  description: JSONP output helper for Sinatra
70
95
  email: serg.podtynnyi@gmail.com
71
96
  executables: []
72
97
  extensions: []
73
98
  extra_rdoc_files: []
74
99
  files:
100
+ - lib/sinatra/jsonp.rb
75
101
  - spec/jsonp_spec.rb
76
102
  - spec/spec_helper.rb
77
- - lib/sinatra/jsonp.rb
78
103
  - README.md
79
104
  - Rakefile
80
105
  - LICENSE
@@ -98,8 +123,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
123
  version: '0'
99
124
  requirements: []
100
125
  rubyforge_project:
101
- rubygems_version: 1.8.11
126
+ rubygems_version: 1.8.24
102
127
  signing_key:
103
128
  specification_version: 3
104
129
  summary: JSONP output helper for Sinatra
105
130
  test_files: []
131
+ has_rdoc: