Fix undefined array key 1 error in sectionsWithAppBlock - #448
Merged
Conversation
Owner
|
@thesunilyadav just some lint issues to fix, rest looks good |
Kyon147
approved these changes
Sep 19, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an "Undefined array key 1" error in the sectionsWithAppBlock method by adding proper validation when extracting schema data from theme assets.
- Added validation to check if
preg_matchfinds a valid schema before accessing array elements - Added test coverage for sections without schema content to prevent regression
- Included a test fixture with invalid schema content to simulate the error condition
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Services/ThemeHelper.php | Added validation check before accessing $matches[1] to prevent undefined array key error |
| tests/Services/ThemeHelperTest.php | Added test case to verify proper handling of sections without valid schema |
| tests/fixtures/get_theme_asset_no_schema.json | Added test fixture with invalid schema content for testing error condition |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Comment on lines
+211
to
216
| if (!empty($matches) && isset($matches[1])) { | ||
| $schema = json_decode($matches[1], true); | ||
| if ($schema && isset($schema['blocks'])) { | ||
| $acceptsAppBlock = in_array('@app', array_column($schema['blocks'], 'type')); | ||
| } | ||
| } |
There was a problem hiding this comment.
The condition !empty($matches) is redundant. When preg_match fails to find a match, $matches will be an empty array, so isset($matches[1]) alone is sufficient to check if the first capture group exists.
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.
Issue: #443
Problem: The
sectionsWithAppBlockmethod throws an "Undefined array key 1" error whenpreg_matchfails to find a schema, causing downstream errors like "Missing auth url".Fix: Added a check to ensure
preg_matchfinds a match before accessing$matches[1]. If no schema exists,$acceptsAppBlockremainsfalse, preventing the error.Testing: Manually verified with schema-less assets; no errors occur, and sections are correctly filtered.
Notes: Please review and let me know if additional tests or changes are needed!