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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e47d761bd19ec78a4558b81ab7018a268bea25545895a67c07f21623699c21ba
4
- data.tar.gz: ee9b112e0a31a4e9646d3e60b02f8c8538440c770dae8c6376031bbad285b7dd
3
+ metadata.gz: 279c8a9ee0783e1a6627cdb320f5b1158861d2b780ba7c04ecfca5b3143d1714
4
+ data.tar.gz: c986b467e5647f3d9fef59636945b5a3beb554b47c89a5fae7bd4b324ed311fb
5
5
  SHA512:
6
- metadata.gz: 3e5682954ac33fa5b7231c50cc59101c4fe811611e21cdc9ffc0eb06d586281692d5bc6c9231f0d553cc4b3cc275640b953cd239d219c46576d2425725f92f72
7
- data.tar.gz: 0be3d40932b255ca70c0101cfd20a5680d5bc01fd61d8d448d27ca9f4c52043d25ec48af172122f30ab28ef4a37315c37f28358feec36edebcf7bf068a24560d
6
+ metadata.gz: 7a4720a9394893df84c2eb8eeb5b39afef82bb07f8b86289ab50fbdec600d874be6c0558ac0fbbb1e42f07fb33fda8bf2b1309dc179485179f3ec14e98b658ae
7
+ data.tar.gz: f70983c80a528a574c5be08037799593928b2c564b04a69f91a0f31be747da183f70bccc7dc9744fe692b5de36dfdb340984e4e306f9f4928031b4cbae612b35
@@ -8,9 +8,13 @@ module Pliny::Helpers
8
8
 
9
9
  def parse_body_params
10
10
  if request.media_type == "application/json"
11
- p = load_params(MultiJson.decode(request.body.read))
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
- p
17
+ load_params(decoded)
14
18
  elsif request.form_data?
15
19
  load_params(request.POST)
16
20
  else
@@ -123,13 +123,17 @@ module Pliny
123
123
  end
124
124
  end
125
125
 
126
- def quote_string(k, v)
126
+ def replace_newlines(v)
127
+ v.gsub("\n", "\\n")
128
+ end
129
+
130
+ def quote_string(v)
127
131
  if !v.include?('"')
128
- %{#{k}="#{v}"}
132
+ %{"#{v}"}
129
133
  elsif !v.include?("'")
130
- %{#{k}='#{v}'}
134
+ %{'#{v}'}
131
135
  else
132
- %{#{k}="#{v.gsub(/"/, '\\"')}"}
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
- if v =~ /\s/
154
- quote_string(k, v)
155
- else
156
- "#{k}=#{v}"
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
@@ -1,3 +1,3 @@
1
1
  module Pliny
2
- VERSION = "0.29.0"
2
+ VERSION = "0.30.0"
3
3
  end
@@ -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
@@ -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.29.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-09-30 00:00:00.000000000 Z
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: []