From 3f78ba80f9d1f1f0e5276c11bfe42a8efad69a29 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 10 Jul 2023 22:05:28 +1000 Subject: [PATCH] Do not require curly bracket in tag name --- Tests/images/xmp_no_prefix.jpg | Bin 0 -> 788 bytes Tests/test_file_jpeg.py | 8 ++++++++ src/PIL/Image.py | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 Tests/images/xmp_no_prefix.jpg diff --git a/Tests/images/xmp_no_prefix.jpg b/Tests/images/xmp_no_prefix.jpg new file mode 100644 index 0000000000000000000000000000000000000000..bcd78c7ed23a62208fc42bd90d8911b33e870e7e GIT binary patch literal 788 zcmex=s)|yBtNcQetFn_V zQHEAm;@P_1sVSzVUPy~A}b>pFhBt#6Eh1d8#@Ol7dKGBRsjYkMrLLv7G_pf78aoD zTA(}wiy*6zqM;+3a9|?4QlW@Z(iUwW$pkka<)WpdpCN3cY31zV>gMj@=@lFj8WtWA8I_!pnwFlCnN?g;T2@|BS=HRq+ScCD*)?hMl&RCE z&zL!D(c&dbmn~nha@D5ITefc7zGLUELx+zXJ$C%W$y1juU%7hi`i+~n9zJ^f@(s#)lOnK WGb1qam<1W^8Gioj(pbR%|0V!ePy~kn literal 0 HcmV?d00001 diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index 904fecebf..217ad74f8 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -898,6 +898,14 @@ class TestFileJpeg: with Image.open("Tests/images/hopper.jpg") as im: assert im.getxmp() == {} + def test_getxmp_no_prefix(self): + with Image.open("Tests/images/xmp_no_prefix.jpg") as im: + if ElementTree is None: + with pytest.warns(UserWarning): + assert im.getxmp() == {} + else: + assert im.getxmp() == {"xmpmeta": {"key": "value"}} + def test_getxmp_padded(self): with Image.open("Tests/images/xmp_padded.jpg") as im: if ElementTree is None: diff --git a/src/PIL/Image.py b/src/PIL/Image.py index a519a28af..6d3715a92 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1380,7 +1380,7 @@ class Image: def _getxmp(self, xmp_tags): def get_name(tag): - return tag.split("}")[1] + return re.sub("^{[^}]+}", "", tag) def get_value(element): value = {get_name(k): v for k, v in element.attrib.items()}