Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(): safeguard extraParam in initialization #8296

Closed
wants to merge 14 commits into from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- chore(): safeguard `extraParam` in initialization [#8296](https://github.com/fabricjs/fabric.js/pull/8296)
- chore(TS): polish text [#8489](https://github.com/fabricjs/fabric.js/pull/8489)
- chore(TS): fix import cycle, extract `groupSVGElements` [#8506](https://github.com/fabricjs/fabric.js/pull/8506)
- chore(TS): permissive `Point` typings [#8434](https://github.com/fabricjs/fabric.js/pull/8434)
Expand Down
5 changes: 4 additions & 1 deletion src/shapes/polyline.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ export class Polyline extends FabricObject {
* top: 100
* });
*/
constructor(points: IPoint[] = [], { left, top, ...options }: any = {}) {
constructor(
points: IPoint[] = [],
{ points: _, left, top, ...options }: any = {}
) {
super({ points, ...options });
this.initialized = true;
this.setBoundingBox(true);
Expand Down
3 changes: 3 additions & 0 deletions test/unit/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
assert.equal(lineWithoutPoints.get('y1'), 0);
assert.equal(lineWithoutPoints.get('x2'), 0);
assert.equal(lineWithoutPoints.get('y2'), 0);

const safeguradedLine = new fabric.Line(undefined, { x1: 1 });
assert.equal(safeguradedLine.get('x1'), 0, 'points should be safeguraded');
});

QUnit.test('complexity', function(assert) {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@

QUnit.test('initialize', function(assert) {
var done = assert.async();
var path = new fabric.Path('M 100 100 L 200 100 L 170 200 z', { top: 0, strokeWidth: 0 });
var path = new fabric.Path('M 100 100 L 200 100 L 170 200 z', { top: 0, strokeWidth: 0, path: 'M 0 0' });

assert.equal(path.left, 100);
assert.equal(path.top, 0);
assert.deepEqual(path.path, fabric.util.parsePath('M 100 100 L 200 100 L 170 200 z'), 'path arg should be safeguraded');
done();
});

Expand Down
2 changes: 2 additions & 0 deletions test/unit/polyline.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@

assert.equal(polyline.type, 'polyline');
assert.deepEqual(polyline.get('points'), [{ x: 10, y: 12 }, { x: 20, y: 22 }]);

assert.deepEqual(new fabric.Polyline(getPoints(), { points: [] }).points, getPoints(), 'points arg should be safeguraded');
});

QUnit.test('complexity', function(assert) {
Expand Down
2 changes: 2 additions & 0 deletions test/unit/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@

assert.equal(text.get('type'), 'text');
assert.equal(text.get('text'), 'x');

assert.ok(new fabric.Text('a', { text: 'b' }).text, 'a', 'text arg should be safeguraded');
});

QUnit.test('toString', function(assert) {
Expand Down