fix: asterisk wildcard generates as invalid key without quotes#44
fix: asterisk wildcard generates as invalid key without quotes#44
Conversation
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
| $key = $this->isValidIdentifier($constName) ? $constName : json_encode($constName); | ||
| $escapedValue = json_encode($value); | ||
| $lines[] = " {$key}: {$escapedValue},"; |
There was a problem hiding this comment.
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.
No description provided.