Bug fix: when calling text() with x as null#1702
Open
culiutudousi wants to merge 3 commits intofoliojs:masterfrom
Open
Bug fix: when calling text() with x as null#1702culiutudousi wants to merge 3 commits intofoliojs:masterfrom
culiutudousi wants to merge 3 commits intofoliojs:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a crash in the text rendering pipeline when text() is called with x explicitly set to null, which previously could result in options becoming null and throwing when reading rotation.
Changes:
- Guard the “treat
xas options object” overload to avoid treatingnullas an options object. - Make
rotationaccess null-safe via optional chaining. - Add an Unreleased changelog entry documenting the fix.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/mixins/text.js | Prevents null from being treated as an options object and avoids null deref when reading rotation. |
| CHANGELOG.md | Documents the fix under “Unreleased”. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
391
to
394
| _initOptions(x = {}, y, options = {}) { | ||
| if (typeof x === 'object') { | ||
| if (x && typeof x === 'object') { | ||
| options = x; | ||
| x = null; |
|
|
||
| - Bump node version requirement to 20+ | ||
| - Bump minimum supported browsers to Firefox 115, iOS/Safari 16 | ||
| - Fix text with input x as null |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Member
|
@culiutudousi please add a simple regression unit test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug fix: when calling text() with input x as null
When calling
text()withxasnulllike:It will raise error as
TypeError: Cannot read properties of null (reading 'rotation').It happens in function
_initOptionsthat whenxisnull:typeof x === 'object'at line 392nullat line 393options.rotationat line 436Actually any of the change line could fix this bug, but I changed both 2 places to make it safer for future.
This bug exists after 0.27.0 when the feature of rotation added with code
result.rotation = Number(options?.rotation ?? 0) % 360;.Checklist:
while this is the first time I contribute in this project, please let me know if I missed any thing