Skip to content

Commit

Permalink
Merge pull request #1175 from FortAwesome/fix-elliptical-arc-flags-pa…
Browse files Browse the repository at this point in the history
…rsing

fix arc flags parsing
  • Loading branch information
Fuzzyma authored Dec 13, 2020
2 parents b2a0e2b + 4980973 commit c01bead
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
34 changes: 34 additions & 0 deletions spec/spec/utils/pathParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,40 @@ describe('pathParser.js', () => {
[ 'L', 0.3, 0.3 ],
[ 'Z' ]
])

// "a" commands without optional whitespace around the flag params and ending coordinate pair
expect(pathParser('a32 32 0 00.03-45.22', false)).toEqual([
[ 'a', 32.0, 32.0, 0.0, 0.0, 0.0, 0.03, -45.22 ],
])

expect(pathParser('a48 48 0 1148-48', false)).toEqual([
[ 'a', 48.0, 48.0, 0.0, 1.0, 1.0, 48.0, -48.0],
])

expect(pathParser('a82.6 82.6 0 0033.48-20.25', false)).toEqual([
[ 'a', 82.6, 82.6, 0.0, 0.0, 0.0, 33.48, -20.25 ],
])

expect(pathParser('a82.45 82.45 0 00-20.24 33.47', false)).toEqual([
[ 'a', 82.45, 82.45, 0.0, 0.0, 0.0, -20.24, 33.47 ],
])

expect(pathParser('a2.51 2.51 0 01.25.32', false)).toEqual([
[ 'a', 2.51, 2.51, 0, 0, 1, 0.25, 0.32 ],
])

expect(pathParser('a2.51 2.51 0 00.25.32', false)).toEqual([
[ 'a', 2.51, 2.51, 0, 0, 0, 0.25, 0.32 ],
])

expect(pathParser('a2.51 2.51 0 000.25.32', false)).toEqual([
[ 'a', 2.51, 2.51, 0, 0, 0, 0.25, 0.32 ],
])

expect(pathParser('a48 48 0 1148-48 48 48 0 01-48 48', false)).toEqual([
[ 'a', 48.0, 48.0, 0.0, 1.0, 1.0, 48.0, -48.0 ],
[ 'a', 48.0, 48.0, 0.0, 0.0, 1.0, -48.0, 48.0 ]
])
})
})
})
5 changes: 4 additions & 1 deletion src/utils/pathParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@ export function pathParser (d, toAbsolute = true) {

if (!isNaN(parseInt(token))) {

if (parser.number === '0' || (parser.inNumber && isArcFlag(parser))) {
if (parser.number === '0' || isArcFlag(parser)) {
parser.inNumber = true
parser.number = token
finalizeNumber(parser, true)
continue
}

parser.inNumber = true
Expand Down

0 comments on commit c01bead

Please sign in to comment.