-
-
Notifications
You must be signed in to change notification settings - Fork 17
fix: check for empty strings and escapement for ID formatting #542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughThe PR tightens validation for ID format strings by requiring an unescaped Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/language/src/validators/function-invocation-validator.ts (1)
93-100: LGTM! The negative lookbehind correctly validates unescaped placeholders.The validation logic correctly:
- Allows undefined formatArg (optional parameter)
- Rejects empty strings (new behavior per PR objectives)
- Requires at least one unescaped
%splaceholder- Handles escaped placeholders like
\%sproperlyThe negative lookbehind
(?<!\\)is an ES2018 feature, which should be well-supported given the project's modern JavaScript/TypeScript stack.Optional: The `g` flag is unnecessary for test()
The
g(global) flag doesn't affect the behavior oftest()when checking for the presence of a pattern. You could simplify to:- !/(?<!\\)%s/g.test(formatArg) + !/(?<!\\)%s/.test(formatArg)However, this is purely a stylistic nitpick with no functional impact.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/language/src/validators/function-invocation-validator.tspackages/language/test/function-invocation.test.tstests/e2e/orm/client-api/generated-id-format-strings.test.ts
🧰 Additional context used
📓 Path-based instructions (1)
tests/e2e/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
E2E tests should validate real-world schema compatibility with established projects
Files:
tests/e2e/orm/client-api/generated-id-format-strings.test.ts
🧠 Learnings (3)
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to tests/**/type*.{ts,tsx} : Ensure TypeScript inference and type coverage are validated through type coverage tests
Applied to files:
packages/language/test/function-invocation.test.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to tests/e2e/**/*.{ts,tsx} : E2E tests should validate real-world schema compatibility with established projects
Applied to files:
packages/language/test/function-invocation.test.tstests/e2e/orm/client-api/generated-id-format-strings.test.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.test.{ts,tsx} : ORM package tests should include comprehensive client API tests and policy tests
Applied to files:
tests/e2e/orm/client-api/generated-id-format-strings.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build-test (22.x, sqlite)
- GitHub Check: build-test (22.x, postgresql)
🔇 Additional comments (4)
packages/language/test/function-invocation.test.ts (2)
151-175: Excellent test coverage for escaped placeholder patterns.The new test cases correctly verify that format strings with both escaped (
\%s) and unescaped (%s) placeholders are accepted, as long as at least one unescaped placeholder exists. These align well with the E2E test expectations.
179-212: Comprehensive invalid format string test coverage.The new error cases correctly validate rejection of:
- Empty format strings
- Format strings with only escaped placeholders (
\%s)- Format strings with incomplete patterns (
%, nos)- Format strings with no placeholders at all
This ensures the validator properly enforces the requirement for at least one unescaped
%s.tests/e2e/orm/client-api/generated-id-format-strings.test.ts (2)
148-149: Schema updates correctly reflect the new validation rules.The removal of the
escapedfield (which presumably contained only escaped%spatterns) and addition ofmixedEscaped2andmixedEscaped3fields align with the validator's requirement for at least one unescaped%splaceholder. These edge cases provide valuable real-world validation of the format string behavior.As per coding guidelines, this E2E test validates real-world schema compatibility with the updated validation rules.
168-172: Test expectations correctly validate escaped vs. unescaped placeholders.The expectations properly verify:
mixedEscaped2: First%sis replaced with UUID,\%sproduces literal%smixedEscaped3: Two escaped\%sproduce literal%s, third%sis replacedThis confirms the end-to-end behavior matches the validator's intent.
ymc9
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
''is no longer accepted as a valid format string.formatarg now properly checks for escapement of%sand throws an error if there are no unescaped%sescapedtest case in the ORM client suite as it did not have an unescaped%s, meaning all rows would be assigned the same ID (this should always be considered an error by ZModel, and is now reported as such).Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.