format_parser 0.13.3 → 0.13.4

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: 6ef925f9f8fdd532ac2020248ca86200a5519243b1d061f9eeded80ef760b15c
4
- data.tar.gz: 71a06ee9fb528d1ff89b2291e85383afa9bb480a048395bc08533271d0355a35
3
+ metadata.gz: f23bfcabe71704fa85eca744312d6b8f48b97087c13cef3129a027b413d2b6ad
4
+ data.tar.gz: df7d94ff90f305b8a65deb7734718035e86494a5eaf129f437ba603f1b2935c8
5
5
  SHA512:
6
- metadata.gz: f1cd0d8851cafd96762449310334b8c2a35e154aba4fbfbab7acae8f58a837f02fc55dea0f877a29a237651a373467226a78ceee2b8fb9f16bbbea97c2870141
7
- data.tar.gz: 3b5ceb254bc8256abe0f53f6ff0f15e357f3c4e381bc82b411cb3fcfd57df368bcf18c3ad914506d7d43a5827a4654d54ceff569a8d39366184d2557bafdfcdf
6
+ metadata.gz: 6beaa829ff6fee1f9a0c83f2ab3478fa1ea64798693d4b1025cb5d225923a0eb65a98c7355a5a15d764b34e51a51cdf8bb43718ea5297b92fc51bb4bceae842b
7
+ data.tar.gz: 2bad249ebf76f964d2a565daf8ec0cfd47176b85ae12c1e9f804575bacc2af0636c12a4291220b0b1f7ae1e4ee66926d9543d77c5aa97707b98abc919231fa6b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.13.4
2
+ * Make sure JSON data never contains NaN, fix the test that was supposed to verify that but didn't
3
+ * Forcibly UTF-8 sanitize all EXIF data when building JSON
4
+
1
5
  ## 0.13.3
2
6
  * Add a fixture to make sure all parsers can cope with an empty file when using `parse_http`
3
7
  * Terminate the ZIP parser early with empty input
@@ -45,8 +45,14 @@ module FormatParser::AttributesJSON
45
45
  def _sanitize_json_value(value, nesting = 0)
46
46
  raise ArgumentError, 'Nested JSON-ish structure too deep' if nesting > MAXIMUM_JSON_NESTING_WHEN_SANITIZING
47
47
  case value
48
- when Float::INFINITY
49
- nil
48
+ when Float
49
+ # Float::NAN cannot be case-matched as it is does not equal itself. Float::INIFINITY can,
50
+ # but it is easier to fold these two into a single case
51
+ if value.nan? || value.infinite?
52
+ nil
53
+ else
54
+ value
55
+ end
50
56
  when String
51
57
  FormatParser.string_to_lossy_utf8(value)
52
58
  when Hash
@@ -59,6 +65,7 @@ module FormatParser::AttributesJSON
59
65
  value
60
66
  end
61
67
  end
68
+ module_function :_sanitize_json_value
62
69
 
63
70
  # Implements to_json with sane defaults, with or without arguments
64
71
  def to_json(*maybe_generator_state)
@@ -1,3 +1,3 @@
1
1
  module FormatParser
2
- VERSION = '0.13.3'
2
+ VERSION = '0.13.4'
3
3
  end
@@ -59,7 +59,9 @@ module FormatParser::EXIFParser
59
59
  end
60
60
 
61
61
  def to_json(*maybe_coder)
62
- __getobj__.to_hash.to_json(*maybe_coder)
62
+ hash_representation = __getobj__.to_hash
63
+ sanitized = FormatParser::AttributesJSON._sanitize_json_value(hash_representation)
64
+ sanitized.to_json(*maybe_coder)
63
65
  end
64
66
 
65
67
  def orientation
@@ -47,7 +47,7 @@ describe FormatParser::AttributesJSON do
47
47
  include FormatParser::AttributesJSON
48
48
  attr_accessor :some_nan
49
49
  def some_nan
50
- (1.0 / 0.0).to_f
50
+ Float::NAN
51
51
  end
52
52
  end
53
53
  instance = anon_class.new
@@ -120,4 +120,14 @@ describe FormatParser::JPEGParser do
120
120
  expect(result.width_px).to eq(2500)
121
121
  expect(result.display_width_px).to eq(1250) # The image is actually rotated
122
122
  end
123
+
124
+ it 'outputs EXIF with binary data in such a way that it can be JSON-serialized' do
125
+ pic_path = fixtures_dir + '/JPEG/exif-with-binary-bytes-in-fields.jpg'
126
+
127
+ result = subject.call(File.open(pic_path, 'rb'))
128
+ expect(result).not_to be_nil
129
+
130
+ serialized = JSON.pretty_generate(result)
131
+ expect(serialized).to be_kind_of(String)
132
+ end
123
133
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: format_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.3
4
+ version: 0.13.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Berman