linebender / linebender/resvg

Percent-encoded non-ASCII image hrefs are not resolved against resources-dir

Open
#1,073 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
4.1k
Forks
348
Avg merge
1d 14h
Merged PRs (30d)
3

Description

## Description

`resvg` does not resolve a local `` resource when the image filename is UTF-8 percent-encoded. This is a practical compatibility issue because SVG editors such as Inkscape may save non-ASCII local filenames in percent-encoded form.

The same local image resolves when the href uses the decoded Unicode filename directly.

## Minimal reproduction

Directory layout:

```text
repro/
url-encoded-image-href.svg
decoded-image-href.svg
images/
细节3-mine.png
```

`url-encoded-image-href.svg`:

```xml

```

`decoded-image-href.svg` is identical except the href is decoded:

```xml

```

`images/细节3-mine.png` can be any valid PNG file.

## Commands run

```powershell
resvg --version
resvg --resources-dir .\repro .\repro\url-encoded-image-href.svg .\repro\cli-encoded.png
resvg --resources-dir .\repro .\repro\decoded-image-href.svg .\repro\cli-decoded.png
```

## Actual behavior

The percent-encoded href emits a warning and the external image is not rendered:

```text
0.47.0
Warning (in usvg::parser::image:110): 'images/%E7%BB%86%E8%8A%823-mine.png' is not a path to an image.
```

In my local reproduction, the encoded output PNG was much smaller than the decoded output, consistent with the child image being omitted:

```text
cli-encoded.png 370 bytes
cli-decoded.png 2267 bytes
```

## Expected behavior

Since `href` is URL/IRI-like and `--resources-dir` is used for resolving relative resources, `resvg` should percent-decode local relative image hrefs before resolving them against `resources_dir`. The encoded href:

```text
images/%E7%BB%86%E8%8A%823-mine.png
```

should resolve to the existing local file:

```text
images/细节3-mine.png
```

## Environment

- `resvg` CLI: `0.47.0`
- OS: Windows

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the two SVG files and the resvg CLI commands using --resources-dir, then inspect the image-resolution path indicated by the usvg::parser::image warning. Verify that the percent-encoded local href resolves to the existing UTF-8 filename and that the encoded and decoded inputs render the external image consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.