From: Ulrich-Matthias Schäfer Date: Sun, 3 Sep 2023 08:49:11 +0000 (+0200) Subject: allow + as delemiter in paths (fixes #1165) X-Git-Tag: 3.2.1~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=06ac034aee7f00f99aec4b55f4a2386371cb5794;p=svg.js.git allow + as delemiter in paths (fixes #1165) --- diff --git a/spec/spec/utils/pathParser.js b/spec/spec/utils/pathParser.js index 15d0453..fdf10c7 100644 --- a/spec/spec/utils/pathParser.js +++ b/spec/spec/utils/pathParser.js @@ -159,6 +159,12 @@ describe('pathParser.js', () => { ['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] ]) + + expect(pathParser('M0+0 L100+0 L50+100')).toEqual([ + ['M', 0, 0], + ['L', 100, 0], + ['L', 50, 100] + ]) }) }) }) diff --git a/src/utils/pathParser.js b/src/utils/pathParser.js index 6d3f4e2..2b97add 100644 --- a/src/utils/pathParser.js +++ b/src/utils/pathParser.js @@ -152,6 +152,7 @@ function isExponential(parser) { return parser.lastToken.toUpperCase() === 'E' } +const pathDelimiters = new Set([' ', ',', '\t', '\n', '\r', '\f']) export function pathParser(d, toAbsolute = true) { let index = 0 let token = '' @@ -201,14 +202,14 @@ export function pathParser(d, toAbsolute = true) { continue } - if (token === ' ' || token === ',') { + if (pathDelimiters.has(token)) { if (parser.inNumber) { finalizeNumber(parser, false) } continue } - if (token === '-') { + if (token === '-' || token === '+') { if (parser.inNumber && !isExponential(parser)) { finalizeNumber(parser, false) --index