Skip to content

Fix undefined array key 1 error in sectionsWithAppBlock - #448

Merged
Kyon147 merged 2 commits into
Kyon147:masterfrom
thesunilyadav:issue-443-fix-schema-regex
Nov 7, 2025
Merged

Fix undefined array key 1 error in sectionsWithAppBlock#448
Kyon147 merged 2 commits into
Kyon147:masterfrom
thesunilyadav:issue-443-fix-schema-regex

Conversation

@thesunilyadav

@thesunilyadav thesunilyadav commented Jul 31, 2025

Copy link
Copy Markdown
Contributor

Issue: #443

Problem: The sectionsWithAppBlock method throws an "Undefined array key 1" error when preg_match fails to find a schema, causing downstream errors like "Missing auth url".

Fix: Added a check to ensure preg_match finds a match before accessing $matches[1]. If no schema exists, $acceptsAppBlock remains false, 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!

@Kyon147

Kyon147 commented Aug 1, 2025

Copy link
Copy Markdown
Owner

@thesunilyadav just some lint issues to fix, rest looks good

@Kyon147
Kyon147 requested a review from Copilot September 19, 2025 09:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_match finds 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'));
}
}

Copilot AI Sep 19, 2025

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@Kyon147
Kyon147 merged commit 97ee84a into Kyon147:master Nov 7, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants