Skip to content

Conversation

thesunilyadav
Copy link

@thesunilyadav thesunilyadav commented Jul 31, 2025

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
Copy link
Owner

Kyon147 commented Aug 1, 2025

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

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

@Copilot Copilot AI left a comment

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'));
}
}
Copy link

Copilot AI Sep 19, 2025

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.

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.

2 participants