Metadata: Add workaround for exif strings containing \n or \r

See: https://github.com/dsoprea/go-exif/issues/55
This commit is contained in:
Michael Mayer 2021-02-13 18:11:44 +01:00
parent aacb524f1e
commit a78a5f6f48
3 changed files with 195 additions and 0 deletions

View file

@ -721,4 +721,36 @@ func TestJSON(t *testing.T) {
assert.Equal(t, "holiday, greetings", data.Subject)
assert.Equal(t, "holiday, greetings", data.Keywords)
})
t.Run("newline.json", func(t *testing.T) {
data, err := JSON("testdata/newline.json", "newline.jpg")
if err != nil {
t.Fatal(err)
}
// t.Logf("all: %+v", data.All)
assert.Equal(t, "Jens\r\tMander", data.Artist)
assert.Equal(t, "0001-01-01T00:00:00Z", data.TakenAt.Format("2006-01-02T15:04:05Z"))
assert.Equal(t, "0001-01-01T00:00:00Z", data.TakenAtLocal.Format("2006-01-02T15:04:05Z"))
assert.Equal(t, "This is the title", data.Title)
assert.Equal(t, "", data.Keywords)
assert.Equal(t, "This is a\n\ndescription!", data.Description)
assert.Equal(t, "This is the world.", data.Subject)
assert.Equal(t, "© 2011 PhotoPrism", data.Copyright)
assert.Equal(t, 567, data.Height)
assert.Equal(t, 850, data.Width)
assert.Equal(t, float32(0), data.Lat)
assert.Equal(t, float32(0), data.Lng)
assert.Equal(t, 30, data.Altitude)
assert.Equal(t, "1/6", data.Exposure)
assert.Equal(t, "Canon", data.CameraMake)
assert.Equal(t, "Canon EOS-1DS", data.CameraModel)
assert.Equal(t, "", data.CameraOwner)
assert.Equal(t, "123456", data.CameraSerial)
assert.Equal(t, 0, data.FocalLength)
assert.Equal(t, 1, data.Orientation)
assert.Equal(t, "", data.Projection)
})
}

View file

@ -44,6 +44,10 @@ func SanitizeString(s string) string {
return ""
}
if strings.HasPrefix(s, "string with binary data") {
return ""
}
s = strings.TrimSpace(s)
return strings.Replace(s, "\"", "", -1)

159
internal/meta/testdata/newline.json vendored Normal file
View file

@ -0,0 +1,159 @@
[{
"SourceFile": "/go/src/github.com/photoprism/photoprism/storage/import/newline.jpg",
"ExifToolVersion": 11.88,
"FileName": "newline.jpg",
"Directory": "/go/src/github.com/photoprism/photoprism/storage/import",
"FileSize": "164 kB",
"FileModifyDate": "2021:02:04 20:03:16+00:00",
"FileAccessDate": "2021:02:12 11:30:59+00:00",
"FileInodeChangeDate": "2021:02:12 10:52:30+00:00",
"FilePermissions": "rw-rw-r--",
"FileType": "JPEG",
"FileTypeExtension": "jpg",
"MIMEType": "image/jpeg",
"JFIFVersion": 1.02,
"ExifByteOrder": "Big-endian (Motorola, MM)",
"ImageDescription": "Hello world\n\nWhere are you?",
"Orientation": "Horizontal (normal)",
"XResolution": 72,
"YResolution": 72,
"ResolutionUnit": "inches",
"Software": "Adobe Photoshop CS Macintosh",
"ModifyDate": "2004:10:07 22:49:16",
"Artist": "Jens\r\tMander",
"Copyright": "© 2004 The World\n...and others",
"ColorSpace": "Uncalibrated",
"ExifImageWidth": 850,
"ExifImageHeight": 567,
"Compression": "JPEG (old-style)",
"ThumbnailOffset": 554,
"ThumbnailLength": 0,
"CurrentIPTCDigest": "91a1c5cf6f1d652b9c9f399b7941af44",
"ApplicationRecordVersion": 2,
"Caption-Abstract": "This is a \r\r caption",
"Writer-Editor": "writer-editor",
"By-line": "by-line",
"ObjectName": "This is the world.",
"CopyrightNotice": "© 2004 The World\n...and others",
"IPTCDigest": "a1a1c5cf6f1d652b9c9f399b7941af41",
"DisplayedUnitsX": "inches",
"DisplayedUnitsY": "inches",
"PrintStyle": "Centered",
"PrintPosition": "0 0",
"PrintScale": 1,
"GlobalAngle": 30,
"GlobalAltitude": 30,
"CopyrightFlag": true,
"URL": "http://www.example.com/",
"URL_List": [],
"SlicesGroupName": "12345_group_name",
"NumSlices": 1,
"PixelAspectRatio": 1,
"HasRealMergedData": "Yes",
"WriterName": "Adobe Photoshop",
"ReaderName": "Adobe Photoshop CS",
"PhotoshopQuality": 8,
"PhotoshopFormat": "Standard",
"ProgressiveScans": "3 Scans",
"XMPToolkit": "XMP toolkit 3.0-28, framework 1.6",
"About": "uuid:112858ee-1a45-11d9-9de3-cfd56dd5c1e3",
"Version": 2.0,
"RawFileName": "raw.tif",
"WhiteBalance": "As Shot",
"Exposure": "+1.30",
"Shadows": 1,
"Brightness": 55,
"Contrast": "+25",
"Saturation": 0,
"Sharpness": 25,
"LuminanceSmoothing": 0,
"ColorNoiseReduction": 25,
"ChromaticAberrationR": 0,
"ChromaticAberrationB": 0,
"VignetteAmount": 0,
"ShadowTint": 0,
"RedHue": 0,
"RedSaturation": 0,
"GreenHue": 0,
"GreenSaturation": 0,
"BlueHue": 0,
"BlueSaturation": 0,
"ExposureTime": "1/6",
"ShutterSpeedValue": "1/6",
"FNumber": 8.0,
"ApertureValue": 8.0,
"ExposureProgram": "Aperture-priority AE",
"ISO": 100,
"DateTimeOriginal": "2004:09:23 10:57:57Z",
"ExposureCompensation": -0.33,
"MeteringMode": "Multi-segment",
"FlashFired": false,
"FlashReturn": "No return detection",
"FocalLength": "17.0 mm",
"SerialNumber": 123456,
"Lens": "17.0-35.0 mm",
"Source": "my-source",
"DateCreated": "2004:09:26",
"CaptionWriter": "caption-writer",
"Credit": "credit",
"City": "city",
"History": "",
"Make": "Canon",
"Model": "Canon EOS-1DS",
"CreateDate": "2004:10:07 22:49:16+02:00",
"MetadataDate": "2004:10:07 22:49:16+02:00",
"CreatorTool": "Adobe Photoshop CS Macintosh",
"DerivedFromDocumentID": "adobe:docid:photoshop:112858ee-1a45-11d9-9de3-cfd56dd5c1e3",
"DerivedFromInstanceID": "uuid:112858ee-1a45-11d9-9de3-cfd56dd5c1e3",
"DocumentID": "adobe:docid:photoshop:112858ee-1a45-11d9-9de3-cfd56dd5c1e3",
"WebStatement": "web-statement",
"Marked": true,
"Creator": "creator",
"Format": "image/jpeg",
"Description": "This is a\n\ndescription!",
"Title": "This is the title",
"Rights": "© 2011 PhotoPrism",
"ProfileCMMType": "Adobe Systems Inc.",
"ProfileVersion": "2.1.0",
"ProfileClass": "Display Device Profile",
"ColorSpaceData": "RGB ",
"ProfileConnectionSpace": "XYZ ",
"ProfileDateTime": "1999:06:03 00:00:00",
"ProfileFileSignature": "signature",
"PrimaryPlatform": "Apple Computer Inc.",
"CMMFlags": "Not Embedded, Independent",
"DeviceManufacturer": "none",
"DeviceModel": "",
"DeviceAttributes": "Reflective, Glossy, Positive, Color",
"RenderingIntent": "Perceptual",
"ConnectionSpaceIlluminant": "0.9642 1 0.82491",
"ProfileCreator": "Adobe Systems Inc.",
"ProfileID": 0,
"ProfileCopyright": "Copyright 1999 Adobe Systems Incorporated",
"ProfileDescription": "Adobe RGB (1998)",
"MediaWhitePoint": "0.95045 1 1.08905",
"MediaBlackPoint": "0 0 0",
"RedTRC": "(Binary data 14 bytes, use -b option to extract)",
"GreenTRC": "(Binary data 14 bytes, use -b option to extract)",
"BlueTRC": "(Binary data 14 bytes, use -b option to extract)",
"RedMatrixColumn": "0.60974 0.31111 0.01947",
"GreenMatrixColumn": "0.20528 0.62567 0.06087",
"BlueMatrixColumn": "0.14919 0.06322 0.74457",
"DCTEncodeVersion": 100,
"APP14Flags0": "(none)",
"APP14Flags1": "(none)",
"ColorTransform": "YCbCr",
"ImageWidth": 850,
"ImageHeight": 567,
"EncodingProcess": "Baseline DCT, Huffman coding",
"BitsPerSample": 8,
"ColorComponents": 3,
"YCbCrSubSampling": "YCbCr4:4:4 (1 1)",
"Aperture": 8.0,
"ImageSize": "850x567",
"Megapixels": 0.482,
"ShutterSpeed": "1/6",
"Flash": "No Flash",
"FocalLength35efl": "17.0 mm",
"LightValue": 8.6
}]