WEB-824: Fix null handling in PrettyPrintPipe#3339
Conversation
Guard against null/undefined/non-string values; return empty string to prevent runtime crash and objects/numbers reaching [innerHTML] consumer. Made-with: Cursor
|
Note
|
| Cohort / File(s) | Summary |
|---|---|
Input Validation Guard src/app/pipes/pretty-print.pipe.ts |
Added null/non-string check at the start of transform method to short-circuit execution and return empty string for invalid inputs, while preserving existing JSON-brace detection and error handling for valid strings. |
Estimated code review effort
🎯 1 (Trivial) | ⏱️ ~3 minutes
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The PR title clearly and specifically describes the main change: adding null handling to the PrettyPrintPipe, which directly addresses the guard clause addition mentioned in the summary. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 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.
Comment @coderabbitai help to get the list of available commands and usage tips.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/app/pipes/pretty-print.pipe.ts (1)
14-17: Consider usingunknowninstead ofanyfor stricter type safety.Per coding guidelines on strict type safety, using
unknownwith proper type guards (which you already have) is preferred overany. Adding an explicit return type also improves clarity.♻️ Suggested type improvements
- transform(value: any) { + transform(value: unknown): string { if (value == null || typeof value !== 'string') { return ''; }Based on learnings: "avoid using Observable as a project-wide pattern... introduce specific interfaces/types... and use proper typing instead of any."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/app/pipes/pretty-print.pipe.ts` around lines 14 - 17, The transform method currently uses a loose any type and lacks an explicit return type; change the parameter type to unknown and add an explicit return type (string) on the transform signature (e.g., transform(value: unknown): string) and keep the existing type guards (value == null || typeof value !== 'string') to safely narrow the type before returning a string; update any callers or tests if they relied on the previous any typing.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/app/pipes/pretty-print.pipe.ts`:
- Around line 14-17: The transform method currently uses a loose any type and
lacks an explicit return type; change the parameter type to unknown and add an
explicit return type (string) on the transform signature (e.g., transform(value:
unknown): string) and keep the existing type guards (value == null || typeof
value !== 'string') to safely narrow the type before returning a string; update
any callers or tests if they relied on the previous any typing.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f15a2358-63f3-488f-ab30-781993b43f10
📒 Files selected for processing (1)
src/app/pipes/pretty-print.pipe.ts
Description:
PrettyPrintPipe calls value.charAt() without validating the input. If the value is null, undefined, or not a string (which can happen with malformed datatable JSON data), the view crashes with a TypeError.
Fix:
Add a guard clause to safely handle null, undefined, and non-string values. Return an empty string when the input is invalid.
Ticket -> https://mifosforge.jira.com/browse/WEB-824?atlOrigin=eyJpIjoiZWMzYTY1MmNiYWUxNDFhMDkyYmZhNTYyYTM4ZjM0NjYiLCJwIjoiaiJ9
Summary by CodeRabbit