Fail of image path resolution in a defs/use context
- Dominant language
- Python
- Stars
- 951
- Forks
- 166
- PR merge metrics
- No merged PRs in 30d
Description
Hello there. I encounter a fail of an image path resolution in a defs/use context
Here is a MWE (env: win10 pro with docker desktop)
The svg file is ok in chrome but fails with cairosvg
**fs step**
- bug.svg
- bug_photo.jpg
- Dockerfile
where bug.svg content is
```xml
```
Dockerfile content is
```dockerfile
FROM python:3.10 AS py
RUN pip install \
ipython \
cairosvg
FROM py
WORKDIR /lab
COPY . "/lab"
# CMD ["ipython"]
CMD ["/bin/bash"]
```
**docker host step**
```shell
docker image build -t o314_cairosvg_python3dot10 .
docker run -it --name o314_cairosvg_python3dot10_inst1 o314_cairosvg_python3dot10
# docker start -ai o314_cairosvg_python3dot10_inst1 # if needed
# docker cp o314_cairosvg_python3dot10_inst1:/lab/bug.png bug.png # if needed
```
**docker container step**
```shell
cairosvg bug.svg -o bug.png -u
```
that turns into a big nasty bug
```
Traceback (most recent call last):
File "/usr/local/lib/python3.10/urllib/request.py", line 1505, in open_local_file
stats = os.stat(localfile)
FileNotFoundError: [Errno 2] No such file or directory: '/bug_photo.jpg'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/cairosvg", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.10/site-packages/cairosvg/__main__.py", line 78, in main
SURFACES[output_format.upper()].convert(**kwargs)
File "/usr/local/lib/python3.10/site-packages/cairosvg/surface.py", line 133, in convert
instance = cls(
File "/usr/local/lib/python3.10/site-packages/cairosvg/surface.py", line 225, in __init__
self.draw(tree)
File "/usr/local/lib/python3.10/site-packages/cairosvg/surface.py", line 472, in draw
self.draw(child)
File "/usr/local/lib/python3.10/site-packages/cairosvg/surface.py", line 472, in draw
self.draw(child)
File "/usr/local/lib/python3.10/site-packages/cairosvg/surface.py", line 404, in draw
TAGS[node.tag](self, node)
File "/usr/local/lib/python3.10/site-packages/cairosvg/defs.py", line 365, in use
surface.draw(tree)
File "/usr/local/lib/python3.10/site-packages/cairosvg/surface.py", line 404, in draw
TAGS[node.tag](self, node)
File "/usr/local/lib/python3.10/site-packages/cairosvg/image.py", line 28, in image
image_bytes = node.fetch_url(url, 'image/*')
File "/usr/local/lib/python3.10/site-packages/cairosvg/parser.py", line 243, in fetch_url
return read_url(url, self.url_fetcher, resource_type)
File "/usr/local/lib/python3.10/site-packages/cairosvg/url.py", line 154, in read_url
return url_fetcher(url, resource_type)
File "/usr/local/lib/python3.10/site-packages/cairosvg/url.py", line 84, in fetch
return urlopen(Request(url, headers=HTTP_HEADERS)).read()
File "/usr/local/lib/python3.10/urllib/request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "/usr/local/lib/python3.10/urllib/request.py", line 519, in open
response = self._open(req, data)
File "/usr/local/lib/python3.10/urllib/request.py", line 536, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/usr/local/lib/python3.10/urllib/request.py", line 496, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.10/urllib/request.py", line 1483, in file_open
return self.open_local_file(req)
File "/usr/local/lib/python3.10/urllib/request.py", line 1522, in open_local_file
raise URLError(exp)
urllib.error.URLError:
```
The jpg path is not resolved correctly
I have tried to trace / fix / debug whatever without success.
Is there any simple things i have missed ? Is it really a bug ?
PS
some point of interests
- https://github.com/Kozea/CairoSVG/blob/main/test_non_regression/svg/struct-image-02-b.svg?short_path=403fdef#L55-L63
- https://github.com/Kozea/CairoSVG/blob/main/cairosvg/parser.py
- https://github.com/Kozea/CairoSVG/blob/main/cairosvg/url.py
- https://github.com/Kozea/CairoSVG/blob/main/cairosvg/image.py
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the reproduction command and inspect cairosvg/parser.py, cairosvg/url.py, and cairosvg/image.py to trace how the image URL is resolved through the defs/use context. Compare the behavior with test_non_regression/svg/struct-image-02-b.svg and its referenced image handling. Done means the supplied SVG resolves bug_photo.jpg correctly and the behavior is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100