Skip to content

Commit a7f0b43

Browse files
committed
Encode POM string to utf-8 before use
* Add new test to ensure Pom objects can be created with strings Signed-off-by: Jono Yang <jyang@nexb.com>
1 parent 4e065e4 commit a7f0b43

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

pymaven/pom.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ def pom_data(self):
420420
creation time, use that client to fetch the POM artifact data remotely.
421421
"""
422422
if self._client is None:
423-
return etree.fromstring(EMPTY_POM.format(self), parser=POM_PARSER)
423+
_pom_data = EMPTY_POM.format(self)
424+
return etree.fromstring(_pom_data.encode('utf-8'), parser=POM_PARSER)
424425

425426
contents = self._client.get_artifact(self.coordinate).contents
426427
with contents as fh:

tests/test_pom.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ def _mock_client(self, *args):
4747
client.get_artifact.side_effect = side_effect
4848
return client
4949

50+
def test_fromstring_without_client(self):
51+
"""Test that a POM object can be created from a string without a client"""
52+
pom = Pom.fromstring("foo:bar:1", FOO_BAR_1_POM)
53+
assert pom.parent.group_id == "foo"
54+
assert pom.parent.artifact_id == "parent"
55+
assert pom.parent.version == "1"
56+
assert pom.parent.properties["groupId"] == "foo"
57+
assert pom.parent.properties["artifactId"] == "parent"
58+
assert pom.parent.properties["version"] == "1"
59+
assert pom.parent.properties["project.groupId"] == "foo"
60+
assert pom.parent.properties["project.artifactId"] == "parent"
61+
assert pom.parent.properties["project.version"] == "1"
62+
assert pom.parent.properties["pom.groupId"] == "foo"
63+
assert pom.parent.properties["pom.artifactId"] == "parent"
64+
assert pom.parent.properties["pom.version"] == "1"
65+
assert pom.properties["parent.groupId"] == "foo"
66+
assert pom.properties["parent.artifactId"] == "parent"
67+
assert pom.properties["parent.version"] == "1"
68+
5069
def test_parent(self):
5170
"""Test pom parent processing"""
5271
client = self._mock_client(FOO_PARENT_1_POM)

0 commit comments

Comments
 (0)