Fix regex to match quoted parameters in parseParams function#209
Open
fadrian06 wants to merge 2 commits into
Open
Fix regex to match quoted parameters in parseParams function#209fadrian06 wants to merge 2 commits into
fadrian06 wants to merge 2 commits into
Conversation
Update regex to match quoted parameters in parseParams function.
There was a problem hiding this comment.
Pull request overview
This PR updates BladeOne’s <x-...> component attribute parsing by changing parseParams() to only match quoted attribute values, improving extraction accuracy and avoiding accidental captures.
Changes:
- Tightened the
parseParams()regex to require attribute values to be enclosed in either single or double quotes.
Comments suppressed due to low confidence (1)
lib/BladeOne.php:3040
- The updated regex now matches single-quoted values, but the extraction logic only removes double quotes. This leaves surrounding single quotes in
$value, producing incorrect compiled params (and can generate invalid PHP when the value contains embedded double-quotes). Strip only the outer matching quote and use a proper PHP string literal for non-:attributes (e.g., viavar_export).
preg_match_all('/([a-zA-Z0-9:-]*?)\s*?=\s*?("?.+?"?|\'?.+?\'?)(\s|$)/ms', $params, $matches);
$paramsCompiled = [];
foreach ($matches[1] as $i => $key) {
$value = str_replace('"', '', $matches[2][$i]);
//its php code
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
This pull request updates the parameter parsing logic in the
parseParamsmethod to better handle quoted parameter values. The regular expression used for matching parameters now supports values wrapped in either single or double quotes, improving robustness when parsing parameters with spaces or special characters.Improvements to parameter parsing:
parseParamsto correctly match parameter values enclosed in single or double quotes, enhancing support for complex parameter values.