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

importJSON function overwrites insert method in path with a variable. #1392

Closed
r03ert0 opened this issue Oct 10, 2017 · 0 comments
Closed

importJSON function overwrites insert method in path with a variable. #1392

r03ert0 opened this issue Oct 10, 2017 · 0 comments
Assignees
Labels
cat: import-export status: PR proposed an active pull request should fix this issue type: bug

Comments

@r03ert0
Copy link

r03ert0 commented Oct 10, 2017

Description/Steps to reproduce

Create an empty path, check whether path.insert is a function (as it should be). Now, import a path using path.importJSON(). path.insert should still be a function, however, it's now a boolean variable assigned the value false. This bug breaks in particular the possibility of running path.divideAt() on the imported path, or any other function that would require path.insert().

Expected result

After path.importJSON(), the function path.insert should still exist, however, it's replaced by a boolean variable.

Additional information

The culprit is this part in paperjs's code:

	importJSON: function(json, target) {
		return Base.deserialize(
				typeof json === 'string' ? JSON.parse(json) : json,
				function(ctor, args, isRoot) {
					var useTarget = isRoot && target
							&& target.constructor === ctor,
						obj = useTarget ? target
							: Base.create(ctor.prototype);
					if (args.length === 1 && obj instanceof Item
							&& (useTarget || !(obj instanceof Layer))) {
						var arg = args[0];
						if (Base.isPlainObject(arg))
							arg.insert = false;
					}
					(useTarget ? obj.set : ctor).apply(obj, args);
					if (useTarget)
						target = null;
					return obj;
				});
	},

arg.insert is overwriting the path.insert function. Replacing arg.insert = false by arg.insertFlag = false, solves the issue of the overwritten path.insert function. In particular, it is now possible to run path.divideAt().

Tested on Mac OS Sierra 10.12.6 (16G29), Chrome 57.0.2987.98 (64-bit).

sasensi added a commit to sasensi/paper.js that referenced this issue Nov 5, 2018
When calling `item.importJSON()`, `item.insert()` was overriden along
with item properties. An exclude object is passed to `Base.set()` to
prevent that from happening.
Closes paperjs#1392
@sasensi sasensi self-assigned this Nov 5, 2018
@sasensi sasensi added the status: PR proposed an active pull request should fix this issue label Nov 26, 2018
@lehni lehni closed this as completed in 0eae0b6 Jun 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat: import-export status: PR proposed an active pull request should fix this issue type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants