Skip to content

Conversation

@markm68k
Copy link

• Ensure that pathBySettingSVGAttributes: always returns a non-null value. • If [self copy] returns nil, return self or create a new instance as a fallback. • Add a comment explaining the fallback.

Thank you for submitting a PR for PocketSVG 😀

  • If you're fixing an issue, please briefly describe the current behaviour and the new behaviour. If you're addressing an open issue, please link to it.

  • If you're introducing a new feature, please briefly describe the new behavior and provide code + sample SVGs for us to see it in action.

Please also add that as an entry in our CHANGELOG.md file to explain your changes and credit yourself. Add the entry in the appropriate section (New Features / Fixes / Internal Change / Breaking Change) under Unreleased. Add links to your GitHub profile and to the related PR and issue after your description. Be part of history.

• Ensure that pathBySettingSVGAttributes: always returns a non-null value.
• If [self copy] returns nil, return self or create a new instance as a fallback.
• Add a comment explaining the fallback.
@markm68k
Copy link
Author

Addresses open issue #229

@markm68k
Copy link
Author

markm68k commented Oct 26, 2025

I'm not certain this is the right fix. However with the current implementation if copy fails, the method will return nil.

Perhaps this is the safest option, as callers can check for nil and handle errors appropriately, avoiding accidental unintended mutations if returning self.

If the decision is to allow returning nil, then changing the header file for pathBySettingSVGAttributes: should be defined as such in the header.

Comment on lines +95 to +96
// Fallback if copy returns nil, ensure non-null return.
path = self;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

falling back to self when self copy returns nil breaks the contract of this method, because callers expect a distinct instance. how about:

Suggested change
// Fallback if copy returns nil, ensure non-null return.
path = self;
// Fallback if copy returns nil, ensure non-null return.
SVGBezierPath *newPath = [SVGBezierPath bezierPathWithCGPath:self.CGPath];
newPath.lineWidth = self.lineWidth;
newPath.flatness = self.flatness;
newPath.miterLimit = self.miterLimit;
path = newPath;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I like this fallback solution much better.

@markm68k markm68k closed this by deleting the head repository Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants