Skip to content

Commit

Permalink
fix: Fixed a bug that SvgDecoder could not recognize when there was c…
Browse files Browse the repository at this point in the history
…omment on the head of the svg file. (#232)
  • Loading branch information
panpf committed Feb 7, 2025
1 parent be0f027 commit 0a2bb7b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Translations: [简体中文](CHANGELOG_zh.md)
prompt for upgrade.
> 3. Reference [《Migration Documentation》](docs/wiki/migrate.md) migrating from 3.x to 4.x
# new

* fix: Fixed a bug that SvgDecoder could not recognize when there was comment on the head of the svg
file. [#232](https://github.com/panpf/sketch/issues/232)

# 4.0.2

* fix: The AsyncImage component is reloaded when the current window size
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
> 2. maven groupId 升级为 `io.github.panpf.sketch4`,因此 2.\*、3.\* 版本不会提示升级
> 3. 参考 [《迁移文档》](docs/wiki/migrate_zh.md) 从 3.x 版本迁移 4.x 版本
# new

* fix: 修复 svg 文件头部有注释时 SvgDecoder 无法识别的
bug。 [#232](https://github.com/panpf/sketch/issues/232)

# 4.0.2

* fix: 当前窗口大小改变时 AsyncImage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class SvgDecoder(
}

private fun isApplicable(fetchResult: FetchResult): Boolean {
// return fetchResult.mimeType == MIME_TYPE || fetchResult.headerBytes.isSvg()
return fetchResult.headerBytes.isSvg()
// Some svg files have comments at the header, which causes the svg tag to be found within 1024 bytes, so first detect mimeType
return fetchResult.mimeType == MIME_TYPE || fetchResult.headerBytes.isSvg()
}

override fun equals(other: Any?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class SvgDecoderTest {
.createDecoderOrNull(sketch, factory) {
it.copy(mimeType = "image/svg+xml")
}.apply {
assertNull(this)
assertTrue(this is SvgDecoder)
}
}

Expand Down

0 comments on commit 0a2bb7b

Please sign in to comment.