diff --git a/imgparse/util.py b/imgparse/util.py index b21c98e..3e24720 100644 --- a/imgparse/util.py +++ b/imgparse/util.py @@ -63,7 +63,7 @@ def get_xmp_data( file_so_far = current_data.decode("latin_1") end_match = re.search(XMP_END, file_so_far) if end_match: - match = re.search(FULL_XMP, file_so_far) + match = re.search(FULL_XMP, file_so_far[: end_match.end()]) if match: xmp_str = match.group(0) break diff --git a/pyproject.toml b/pyproject.toml index 9e8bca1..358d506 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "imgparse" -version = "2.0.6" +version = "2.0.7" description = "Python image-metadata-parser utilities" authors = [] include = [ diff --git a/tests/data/2xmpendtags.jpg b/tests/data/2xmpendtags.jpg new file mode 100644 index 0000000..56962f3 Binary files /dev/null and b/tests/data/2xmpendtags.jpg differ diff --git a/tests/test_imgparse.py b/tests/test_imgparse.py index 6d90b22..66f58b3 100644 --- a/tests/test_imgparse.py +++ b/tests/test_imgparse.py @@ -129,6 +129,11 @@ def s3_image_parser() -> MetadataParser: ) +@pytest.fixture +def two_xmp_end_tags_parser() -> MetadataParser: + return MetadataParser(base_path / "2xmpendtags.jpg") + + def test_get_camera_params_dji(dji_parser: MetadataParser) -> None: pitch1 = dji_parser.pixel_pitch_meters() focal1 = dji_parser.focal_length_meters() @@ -671,3 +676,9 @@ def s3_chunk_side_effect(Range=None, **kwargs): # type: ignore s3_image_parser._xmp_data = None s3_image_parser._raw_data = b"" s3_image_parser.rotation() + + +def test_multiple_xmp_end_tags( + two_xmp_end_tags_parser: MetadataParser, +) -> None: + assert two_xmp_end_tags_parser.xmp_data is not None