Skip to content

fix: asterisk wildcard generates as invalid key without quotes#44

Merged
shavonn merged 3 commits intomainfrom
fix-wildcard-ts-gen
Jan 28, 2026
Merged

fix: asterisk wildcard generates as invalid key without quotes#44
shavonn merged 3 commits intomainfrom
fix-wildcard-ts-gen

Conversation

@shavonn
Copy link
Contributor

@shavonn shavonn commented Jan 28, 2026

No description provided.

Copilot AI review requested due to automatic review settings January 28, 2026 15:11
Copy link
Contributor

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

Fixes TypeScript generation when permissions include * wildcards by ensuring generated object keys are valid TypeScript identifiers.

Changes:

  • Add constant-name sanitization so wildcard permissions like * / article:* generate valid identifiers (e.g., WILDCARD) instead of invalid bare * keys.
  • Update name parsing to apply sanitization for both prefixed (article:*) and non-prefixed (*) names.
  • Add a feature test covering wildcard permissions emitted from database records.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/Feature/Commands/TypeScriptCommandTest.php Adds a regression test asserting wildcard permissions produce valid TS keys and no bare *: properties.
src/Commands/TypeScriptCommand.php Sanitizes generated constant names (including wildcards) to valid TypeScript identifiers before emitting object keys.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…, which properly escapes quotes, backslashes, newlines, unicode, and any other special characters
@shavonn shavonn requested a review from Copilot January 28, 2026 23:01
@shavonn shavonn merged commit 2d2104f into main Jan 28, 2026
21 checks passed
@shavonn shavonn deleted the fix-wildcard-ts-gen branch January 28, 2026 23:04
Copy link
Contributor

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +379 to +381
$key = $this->isValidIdentifier($constName) ? $constName : json_encode($constName);
$escapedValue = json_encode($value);
$lines[] = " {$key}: {$escapedValue},";
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

json_encode() can return false (e.g., on invalid UTF-8) which would produce invalid TypeScript output (empty key/value or false string coercion). Consider using json_encode(..., JSON_THROW_ON_ERROR) (and handling the exception) or otherwise asserting the return type is a string before writing it into the generated file.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant