`exiv2 -m file` / `exiv2 -M` cannot handle whitespaces value
iblazhko opened this issue · comments
Describe the bug
exiv2 -m file
fails when value is filled with whitespaces.
To Reproduce
Create commands file metadata.txt
with following content:
set Exif.Photo.Flash Short 0
set Exif.Photo.FocalLength Rational 350/10
set Exif.Photo.FocalLengthIn35mmFilm Short 35
set Exif.Photo.LensSpecification Rational 350/10 350/10 140/100 140/100
set Exif.Photo.LensMake Ascii
set Exif.Photo.LensModel Ascii 35mm f/1.4E
(note the whitespaces in Exif.Photo.LensMake
line)
Try to apply this metadata to an image:
exiv2 -m metadata.txt image.jpg
Error:
metadata.txt, line 5: Invalid command line
exiv2: Error parsing -m option arguments
Usage: exiv2 [ option [ arg ] ]+ [ action ] file ...
Expected behavior
Specified value is applied as is, or an empty string is applied.
Desktop (please complete the following information):
- OS and version: macOS 14.1.1 / arm64
- Exiv2 version and source: exiv2 0.28.1 via Homebrew
- Compiler and version: N/A
- Compilation mode and/or compiler flags: N/A
Additional context
Can also be reproduced with exiv2 -M "set Exif.Photo.LensMake Ascii " image.jpg
(note the space before closing "
, exiv2 -M "set Exif.Photo.LensMake Ascii" image.jpg
or exiv2 -M "set Exif.Photo.LensMake Ascii ''" image.jpg
work fine).
Looks like a regression, I believe previous version was able to process same command, or maybe previous version trimmed -PVk -K
output - I have a script I use to selectively copy Exif metadata, and noticed that it started to fail with some files I was able to process before.
In case this may be useful to someone having the same issue: as a workaround, I am piping exiv2 -PVk
output through sed
to trim trailing whitespaces, result can be processed by exiv2 -m-
:
exiv2 -PVk \
-K Exif.Image.DateTime \
-K Exif.Image.Make \
-K Exif.Image.Model \
-K Exif.Photo.LensMake \
-K Exif.Photo.LensModel \
source.jpg \
| sed -e 's/[[:space:]]*$//' \
| exiv2 -m- target.jpg
I was about to state, that it may not be a bug, but rather a feature. But found this on the manual:
In the file, any blank lines or additional white space is ignored and any lines beginning with a # are comments.
Also, from the same manual:
value The remaining text on the line is the value, and can optionally be enclosed in quotes (see Quotations with 'modify' commands). For Ascii, XmpAlt, XmpBag, XmpSeq and XmpText, the value is optional which is equivalent to an empty value ("")
So, it's seams like expected behavior is not to differentiate between the following of examples You've provided:
exiv2 -M "set Exif.Photo.LensMake Ascii " image.jpg
exiv2 -M "set Exif.Photo.LensMake Ascii" image.jpg
Relevant (I guess) parts of the source:
- https://github.com/Exiv2/exiv2/blob/main/app/exiv2.cpp#L1234-L1257 (reading the lines)
- https://github.com/Exiv2/exiv2/blob/main/app/exiv2.cpp#L1302-L1426 (parsing the line)
- https://github.com/Exiv2/exiv2/blob/main/app/exiv2.cpp#L1363-L1405 (parsing the value, I guess the culprit is here)
Thanks for confirming my assumptions.
Whatever the parsing rules are, I think it is a fair expectation that exiv2 -m
should be able to consume what exiv2 -Pvk
produces.