Skip to content

Conversation

@x04
Copy link
Contributor

@x04 x04 commented Nov 5, 2025

elysiajs/elysia#1527 ref issue

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of bracket notation and special characters in property names.
    • Fixed optional property access and deletion logic for objects and arrays.
  • Tests

    • Added test coverage for bracket notation in property names.

@coderabbitai
Copy link

coderabbitai bot commented Nov 5, 2025

Walkthrough

The changes enhance property access handling in src/index.ts to support bracket notation in property names and refine optional property deletion logic by removing explicit dots before optional properties in computed target strings.

Changes

Cohort / File(s) Summary
Optional Property Deletion Logic
src/index.ts
Updated isSpecialProperty to treat dots, brackets, and combinations as special characters. Modified deletion target generation to remove explicit dots before optional properties (e.g., .{opt}{opt}), affecting both object and array handling. Enhanced root-level optional property extraction to support both dot and bracket notation with optional chaining normalization.
Bracket Notation Test Coverage
test/index.test.ts
Added new test case "handle bracket notation in property names" to verify schema support for property names containing brackets (e.g., order[createdAt], orderBy[createdAt]). Test validates that only bracketed keys with optional union constraints are accepted and preserved in sanitized output.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • String manipulation logic for deletion targets requires careful verification across edge cases
  • Bracket notation and optional chaining normalization handling needs testing with various property name patterns
  • Test coverage should be validated to ensure bracket notation cases are comprehensive

Poem

🐰 Brackets dance where dots once played,
Optional chains in code parade,
Special properties now stand tall,
Bracket notation conquers all!
✨ Deletion logic made pristine,
Simplest access ever seen!

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix bracket handling in fields' directly aligns with the main changes, which focus on fixing how bracket notation is handled in property names and field access patterns.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7eb3c39 and f037e8a.

📒 Files selected for processing (2)
  • src/index.ts (4 hunks)
  • test/index.test.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/index.test.ts (1)
test/utils.ts (1)
  • isEqual (9-18)
🔇 Additional comments (3)
test/index.test.ts (1)

310-333: LGTM! Well-structured test for bracket notation.

The test correctly validates that property names containing brackets (like 'order[createdAt]') are properly handled when defined as optional union types, and that additional properties are correctly filtered out.

src/index.ts (2)

8-8: LGTM! Correctly expands special property detection.

Adding \[ and \] to the regex properly identifies property names containing brackets as special, ensuring they're accessed using bracket notation.


125-125: LGTM! Correctly removes redundant dot in deletion targets.

Removing the explicit dot is necessary since optionals[oi] now contains the complete property accessor (either .field or ["field"]). This prevents generating invalid syntax like ar0v[ar0s[i]]..field.

Also applies to: 464-464

@SaltyAom SaltyAom merged commit ded195c into elysiajs:main Nov 5, 2025
2 checks passed
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.

2 participants