korlibs / korlibs/korlibs-image

NumberFormatException: For input string: "-" in korim-jvm:2.0.6, vector, format, SVG - tokenizePath.StrReader.readNumber(): Double

Open
#10 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Kotlin
Stars
2
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Our project will be processing 100's of SVG files, and a few of these files include a command to change [stroke-width] embedded in the path such as this example:
`"''`

I have made temporary decision to simply replace "stroke-width" with "I" (for I)gnore for now) and this is being duly
dropped by tokeinizePath.StrReader() without complications.

This takes care of our immediate issue. As we are handling the Path extraction ourselves we can give this special
attention in the future, it is of no immediate concern.

If this is NOT to be considered a valid command we would like to be informed of the basis of the decision.

IF it is viable to include a CMND:stroke-width inside the Path (it must be?) then the following code will work to protect from this or other commands with "-" from causing fatal errors:

```
return if (str.isEmpty() || (str.length == 1 && str[0] == '-')) 0.0 else try {
str.toDouble()
} catch (e: Throwable) {
e.printStackTrace()
0.0
}
```

The original file causing the (down stream) Error is this one, name: Mine (how appropriate?!)

[mine.svg.txt](https://github.com/korlibs/korge/files/5957735/mine.svg.txt)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in tokenizePath.StrReader.readNumber() and reproduce the NumberFormatException with the linked mine.svg.txt input. Check how the SVG path is tokenized around stroke-width and the standalone "-"; done means valid SVG input no longer causes this parsing failure, with behavior confirmed by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.