fix: safely parse portal URL hash params to prevent crash#26910
fix: safely parse portal URL hash params to prevent crash#26910Rohit7241 wants to merge 2 commits intoTryGhost:mainfrom
Conversation
|
You have used all of your free Bugbot PR reviews. To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial. |
WalkthroughThe change introduces a 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/portal/src/app.js`:
- Around line 29-37: In safeJSONParse, replace the incorrect JSON.Parse call
with the correct JSON.parse to avoid the TypeError and allow valid JSON to
parse; update the return statement inside the try block to call
JSON.parse(value) (leaving fallback behavior and the warning in the catch
unchanged) and run a quick smoke test to confirm valid URL JSON now returns
parsed objects from safeJSONParse.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 922cbdf1-8266-4144-8353-41bdb1ca2586
📒 Files selected for processing (1)
apps/portal/src/app.js
| function safeJSONParse(value, fallback = null) { | ||
| try { | ||
| return JSON.Parse(value); | ||
| } catch (e) { | ||
| /* eslint-disable no-console */ | ||
| console.warn('[Portal] Invalid JSON in URL parameter:', e.message); | ||
| return fallback; | ||
| } | ||
| } |
There was a problem hiding this comment.
Critical: JSON.Parse is not a valid function — should be JSON.parse.
JavaScript is case-sensitive. JSON.Parse does not exist and will throw TypeError: JSON.Parse is not a function on every call. This causes all valid JSON to fall through to the catch block, returning null and defeating the entire purpose of this fix.
🐛 Proposed fix
function safeJSONParse(value, fallback = null) {
try {
- return JSON.Parse(value);
+ return JSON.parse(value);
} catch (e) {
/* eslint-disable no-console */
console.warn('[Portal] Invalid JSON in URL parameter:', e.message);
return fallback;
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function safeJSONParse(value, fallback = null) { | |
| try { | |
| return JSON.Parse(value); | |
| } catch (e) { | |
| /* eslint-disable no-console */ | |
| console.warn('[Portal] Invalid JSON in URL parameter:', e.message); | |
| return fallback; | |
| } | |
| } | |
| function safeJSONParse(value, fallback = null) { | |
| try { | |
| return JSON.parse(value); | |
| } catch (e) { | |
| /* eslint-disable no-console */ | |
| console.warn('[Portal] Invalid JSON in URL parameter:', e.message); | |
| return fallback; | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/portal/src/app.js` around lines 29 - 37, In safeJSONParse, replace the
incorrect JSON.Parse call with the correct JSON.parse to avoid the TypeError and
allow valid JSON to parse; update the return statement inside the try block to
call JSON.parse(value) (leaving fallback behavior and the warning in the catch
unchanged) and run a quick smoke test to confirm valid URL JSON now returns
parsed objects from safeJSONParse.
🐛 Fixed portal URL hash parsing to prevent crash
closes #26399
The previous implementation of parsing URL hash parameters could
throw errors if the hash was malformed or missing. This change
introduces a safe JSON parse utility that ensures invalid or empty
hashes do not crash the portal. This improves stability and prevents
unexpected runtime errors for users navigating with unusual URLs.