pliny 0.29.0 → 0.30.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pliny/helpers/params.rb +6 -2
- data/lib/pliny/log.rb +12 -9
- data/lib/pliny/version.rb +1 -1
- data/spec/helpers/params_spec.rb +8 -0
- data/spec/log_spec.rb +6 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 279c8a9ee0783e1a6627cdb320f5b1158861d2b780ba7c04ecfca5b3143d1714
|
4
|
+
data.tar.gz: c986b467e5647f3d9fef59636945b5a3beb554b47c89a5fae7bd4b324ed311fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a4720a9394893df84c2eb8eeb5b39afef82bb07f8b86289ab50fbdec600d874be6c0558ac0fbbb1e42f07fb33fda8bf2b1309dc179485179f3ec14e98b658ae
|
7
|
+
data.tar.gz: f70983c80a528a574c5be08037799593928b2c564b04a69f91a0f31be747da183f70bccc7dc9744fe692b5de36dfdb340984e4e306f9f4928031b4cbae612b35
|
data/lib/pliny/helpers/params.rb
CHANGED
@@ -8,9 +8,13 @@ module Pliny::Helpers
|
|
8
8
|
|
9
9
|
def parse_body_params
|
10
10
|
if request.media_type == "application/json"
|
11
|
-
|
11
|
+
begin
|
12
|
+
decoded = MultiJson.decode(request.body.read)
|
13
|
+
rescue MultiJson::ParseError => e
|
14
|
+
raise Pliny::Errors::BadRequest, e.message
|
15
|
+
end
|
12
16
|
request.body.rewind
|
13
|
-
|
17
|
+
load_params(decoded)
|
14
18
|
elsif request.form_data?
|
15
19
|
load_params(request.POST)
|
16
20
|
else
|
data/lib/pliny/log.rb
CHANGED
@@ -123,13 +123,17 @@ module Pliny
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
def
|
126
|
+
def replace_newlines(v)
|
127
|
+
v.gsub("\n", "\\n")
|
128
|
+
end
|
129
|
+
|
130
|
+
def quote_string(v)
|
127
131
|
if !v.include?('"')
|
128
|
-
%{
|
132
|
+
%{"#{v}"}
|
129
133
|
elsif !v.include?("'")
|
130
|
-
%{
|
134
|
+
%{'#{v}'}
|
131
135
|
else
|
132
|
-
%{
|
136
|
+
%{"#{v.gsub(/"/, '\\"')}"}
|
133
137
|
end
|
134
138
|
end
|
135
139
|
|
@@ -150,11 +154,10 @@ module Pliny
|
|
150
154
|
"#{k}=#{v.iso8601}"
|
151
155
|
else
|
152
156
|
v = "#{v}"
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
end
|
157
|
+
v = replace_newlines(v)
|
158
|
+
v = quote_string(v) if v =~ /\s/
|
159
|
+
|
160
|
+
"#{k}=#{v}"
|
158
161
|
end
|
159
162
|
end
|
160
163
|
end
|
data/lib/pliny/version.rb
CHANGED
data/spec/helpers/params_spec.rb
CHANGED
@@ -34,4 +34,12 @@ describe Pliny::Helpers::Params do
|
|
34
34
|
post "/", "<hello>world</hello>", {"CONTENT_TYPE" => "application/xml"}
|
35
35
|
assert_equal "{}", last_response.body
|
36
36
|
end
|
37
|
+
|
38
|
+
it "should throw bad request when receiving invalid json via post" do
|
39
|
+
err = assert_raises(Pliny::Errors::BadRequest) do
|
40
|
+
post "/", "{\"foo\"}", {"CONTENT_TYPE" => "application/json"}
|
41
|
+
end
|
42
|
+
|
43
|
+
assert_match /unexpected token/, err.message
|
44
|
+
end
|
37
45
|
end
|
data/spec/log_spec.rb
CHANGED
@@ -161,6 +161,12 @@ describe Pliny::Log do
|
|
161
161
|
Pliny.log(foo: "string with spaces")
|
162
162
|
end
|
163
163
|
|
164
|
+
it "replaces newlines in strings" do
|
165
|
+
expect(@io).to receive(:print).with("foo=\"string\\nwith newlines\\n\"\n")
|
166
|
+
|
167
|
+
Pliny.log(foo: "string\nwith newlines\n")
|
168
|
+
end
|
169
|
+
|
164
170
|
it "by default interpolates objects into strings" do
|
165
171
|
expect(@io).to receive(:print).with("foo=message\n")
|
166
172
|
expect(@io).to receive(:print).with("foo=42\n")
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pliny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.30.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur Leach
|
8
8
|
- Pedro Belo
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-12-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -503,7 +503,7 @@ homepage: https://github.com/interagent/pliny
|
|
503
503
|
licenses:
|
504
504
|
- MIT
|
505
505
|
metadata: {}
|
506
|
-
post_install_message:
|
506
|
+
post_install_message:
|
507
507
|
rdoc_options: []
|
508
508
|
require_paths:
|
509
509
|
- lib
|
@@ -519,7 +519,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
519
519
|
version: '0'
|
520
520
|
requirements: []
|
521
521
|
rubygems_version: 3.0.3
|
522
|
-
signing_key:
|
522
|
+
signing_key:
|
523
523
|
specification_version: 4
|
524
524
|
summary: Basic tooling to support API apps in Sinatra
|
525
525
|
test_files: []
|