Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Decode exception on HGMO content #11

Open
La0 opened this issue Jan 7, 2020 · 3 comments
Open

Decode exception on HGMO content #11

La0 opened this issue Jan 7, 2020 · 3 comments

Comments

@La0
Copy link
Contributor

La0 commented Jan 7, 2020

Happens in Docker using python:3-alpine (i discovered that running on Heroku):

To reproduce, write that file as crash.py:

from parsepatch.patch import Patch
import requests
r = requests.get('https://hg.mozilla.org/try/raw-rev/5812353e06c977115314cf979e2909ab4eab21b4')
Patch.parse_patch(r.content)

Then run as:

docker run -it -v $(pwd)/crash.py:/crash.py python:3-alpine sh

In the docker shell:

pip install -q requests parsepatch six
python /crash.py

You should get the following exception:

Traceback (most recent call last):
  File "/crash.py", line 4, in <module>
    Patch.parse_patch(r.content)
  File "/usr/local/lib/python3.7/site-packages/parsepatch/patch.py", line 84, in parse_patch
    return p.parse()
  File "/usr/local/lib/python3.7/site-packages/parsepatch/patch.py", line 342, in parse
    while self.next_diff():
  File "/usr/local/lib/python3.7/site-packages/parsepatch/patch.py", line 206, in next_diff
    for line in self.get_lines:
  File "/usr/local/lib/python3.7/site-packages/parsepatch/patch.py", line 129, in _lines
    if self._check(line):
  File "/usr/local/lib/python3.7/site-packages/parsepatch/patch.py", line 150, in _check
    return self.conditions[-1](line)
  File "/usr/local/lib/python3.7/site-packages/parsepatch/patch.py", line 205, in <lambda>
    self._condition(lambda x: not x.startswith('diff --git a/') and not x.startswith('diff -r '))
AttributeError: 'int' object has no attribute 'startswith'

Which does not happen with Patch.parse_patch(r.content.decode('utf-8'))

@marco-c
Copy link
Collaborator

marco-c commented Jan 7, 2020

Example?

@marco-c marco-c transferred this issue from mozilla/pyo3-parsepatch Jan 7, 2020
@La0
Copy link
Contributor Author

La0 commented Jan 7, 2020

It works if we use r.text though.

@marco-c
Copy link
Collaborator

marco-c commented Jan 7, 2020

It works if we use r.text though.

That's equivalent to using r.content.decode("utf-8", "replace").

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants