Crash for currentColor

Open
#67 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
swift

Research direction

Start with SVGColor.parseColor(::) and reproduce the crash using the SVG in the issue, especially its root style and currentColor attributes. Trace how the color lookup handles currentColor when it resolves to another currentColor. Done means the supplied SVG parses without recursion or a crash and its color is resolved consistently.

Written by the indexing model from the issue text.

Description

this is the test svg:

<svg width="16" height="24" viewBox="0 0 16 24" style="color: red;" xmlns="http://www.w3.org/2000/svg">
  <g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" color="currentColor"><path d="M5.533 17c-1.422 2.006-1.78 3.065-1.38 3.916q.06.126.14.243C4.862 22 6.34 22 9.295 22h5.408c2.955 0 4.432 0 5.004-.841q.08-.118.139-.243c.4-.85.042-1.91-1.38-3.916"/><path d="M12.998 7h-1.996c-2.87 0-4.805 3.07-3.674 5.828a1 1 0 0 0 .918.633h.703c.237 0 .444.17.501.41l.905 3.786c.189.79.867 1.343 1.645 1.343s1.456-.554 1.645-1.343l.905-3.786a.52.52 0 0 1 .5-.41h.704a1 1 0 0 0 .918-.633C17.804 10.069 15.869 7 12.999 7"/><path d="M14.5 4.5a2.5 2.5 0 1 1-5 0a2.5 2.5 0 0 1 5 0"/></g>
</svg>

it seems not parse style in svg tag, and will recursive at this function:

    static func parseColor(_ string: String, _ style: [String: String]) -> SVGColor? {
        let normalized = string.replacingOccurrences(of: " ", with: "")
        if normalized == "none" || normalized == "transparent" {
            return .none
        } else if normalized == "currentColor", let currentColor = style["color"] {
            return parseColor(currentColor, style)
        } else if let defaultColor = SVGColor.by(name: normalized) {
            return defaultColor
        } else if normalized.hasPrefix("rgb") {
            return parseRGBNotation(colorString: normalized)
        } else {
            return createColorFromHex(normalized)
        }
    }
Dominant language
Swift
Stars
853
Forks
112
PR merge metrics
No merged PRs in 30d

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.

More from exyte/SVGView

All issues in exyte/SVGView

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.