fix path arc parsing without separators

This commit is contained in:
Anton Lavrenov
2025-08-23 13:43:09 -05:00
parent e2c0a719b9
commit cc4e2acd3b
2 changed files with 46 additions and 2 deletions

View File

@@ -515,8 +515,36 @@ export class Path extends Shape<PathConfig> {
str = str.slice(1);
coords.length = 0;
while ((match = re.exec(str))) {
coords.push(match[0]);
if (c === 'a' || c === 'A') {
let i = 0;
while (i < str.length) {
// skip separators
while (i < str.length && (str[i] === ',' || str[i] === ' ')) {
i++;
}
if (i >= str.length) {
break;
}
const idx = coords.length % 7;
if (idx === 3 || idx === 4) {
// flags are single-digit values (0 or 1)
coords.push(str[i]);
i++;
} else {
let s = '';
if (str[i] === '-' || str[i] === '+') {
s += str[i++];
}
while (i < str.length && /[0-9.]/.test(str[i])) {
s += str[i++];
}
coords.push(s);
}
}
} else {
while ((match = re.exec(str))) {
coords.push(match[0]);
}
}
// while ((match = re.exec(str))) {

View File

@@ -60,6 +60,22 @@ describe('Path', function () {
assert.equal(path.getClassName(), 'Path');
});
it('parses arc without separators after flags', function () {
const path = new Konva.Path({
data: 'M19.5 10.5c0 7.142-7.5 11.25-7.5 11.25S4.5 17.642 4.5 10.5a7.5 7.5 0 1115 0z',
});
const arc = path.dataArray[3];
assert.equal(arc.command, 'A');
assert.closeTo(arc.points[0], 12, 0.001);
assert.closeTo(arc.points[1], 10.5, 0.001);
assert.closeTo(arc.points[2], 7.5, 0.001);
assert.closeTo(arc.points[3], 7.5, 0.001);
assert.closeTo(arc.points[4], Math.PI, 0.001);
assert.closeTo(arc.points[5], Math.PI, 0.001);
assert.equal(arc.points[6], 0);
assert.equal(arc.points[7], 1);
});
// ======================================================
it('add path with line cap and line join', function () {
var stage = addStage();