Skip to content

Pom.fromstring() crashes when creating a Pom object from a string in pymaven-patch #2220

Description

@JonoYang

I get the error message ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration. when I run the following code:

>>> FOO_BAR_1_POM = """\
... <?xml version="1.0" encoding="UTF-8"?>
... <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
...     <modelVersion>4.0.0</modelVersion>
...     <parent>
...         <groupId>foo</groupId>
...         <artifactId>parent</artifactId>
...         <version>1</version>
...     </parent>
...     <artifactId>bar</artifactId>
...     <properties>
...         <bazChild>${bazVersion}</bazChild>
...         <resolveProp>resolve</resolveProp>
...     </properties>
... </project>
... """
>>> from pymaven.pom import Pom
>>> p = Pom.fromstring('foo:bar:1', FOO_BAR_1_POM)
>>> p.parent.properties['groupId']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jono/nexb/src/pymaven/pymaven/utils.py", line 50, in wrapper
    setattr(slf, name, func(slf, *args, **kwargs))
  File "/home/jono/nexb/src/pymaven/pymaven/pom.py", line 437, in properties
    if isinstance(self.parent, Pom):
  File "/home/jono/nexb/src/pymaven/pymaven/utils.py", line 50, in wrapper
    setattr(slf, name, func(slf, *args, **kwargs))
  File "/home/jono/nexb/src/pymaven/pymaven/pom.py", line 408, in parent
    parent = _find(self.pom_data, "parent")
  File "/home/jono/nexb/src/pymaven/pymaven/utils.py", line 50, in wrapper
    setattr(slf, name, func(slf, *args, **kwargs))
  File "/home/jono/nexb/src/pymaven/pymaven/pom.py", line 423, in pom_data
    return etree.fromstring(EMPTY_POM.format(self), parser=POM_PARSER)
  File "src/lxml/etree.pyx", line 3237, in lxml.etree.fromstring
  File "src/lxml/parser.pxi", line 1891, in lxml.etree._parseMemoryDocument
ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.

The issue is at https://github.com/nexB/pymaven/blob/v0.2.9.patch-branch/pymaven/pom.py#L423, where the formatted POM string should be encoded to utf-8 before use.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions