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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/attributes_json.rb +9 -2
- data/lib/format_parser/version.rb +1 -1
- data/lib/parsers/exif_parser.rb +3 -1
- data/spec/attributes_json_spec.rb +1 -1
- data/spec/parsers/jpeg_parser_spec.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f23bfcabe71704fa85eca744312d6b8f48b97087c13cef3129a027b413d2b6ad
|
4
|
+
data.tar.gz: df7d94ff90f305b8a65deb7734718035e86494a5eaf129f437ba603f1b2935c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/attributes_json.rb
CHANGED
@@ -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
|
49
|
-
|
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)
|
data/lib/parsers/exif_parser.rb
CHANGED
@@ -59,7 +59,9 @@ module FormatParser::EXIFParser
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def to_json(*maybe_coder)
|
62
|
-
__getobj__.to_hash
|
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
|
@@ -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
|