fix: ensureSecureProtocol removing '//' inside URL paths#7064
fix: ensureSecureProtocol removing '//' inside URL paths#7064vmridul wants to merge 3 commits intoRocketChat:developfrom
Conversation
WalkthroughFixed a bug in the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested labels
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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.
🧹 Nitpick comments (1)
app/lib/methods/helpers/ensureSecureProtocol.test.ts (1)
20-23: Good test coverage for the bug fix!The test clearly validates that double slashes within the URL path are preserved while
https://is prepended.💡 Optional: Consider adding a test for the combined scenario
To ensure both the leading
//stripping and internal//preservation work together, consider adding:it('strips leading double slashes while preserving double slashes in the path', () => { const linkWithBoth = '//www.google.com/docs//api'; expect(ensureSecureProtocol(linkWithBoth)).toBe('https://www.google.com/docs//api'); });This would verify that the fix handles URLs that have both leading
//(like the test on line 17) and internal//(like your new test) simultaneously.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/lib/methods/helpers/ensureSecureProtocol.test.ts` around lines 20 - 23, Add a new test to cover the combined scenario where a URL has leading double slashes and internal double slashes: call ensureSecureProtocol with the string '//www.google.com/docs//api' and assert it returns 'https://www.google.com/docs//api' so the function both strips the leading '//' and preserves internal '//' in the path; place this alongside the existing tests in ensureSecureProtocol.test.ts and reference the ensureSecureProtocol function.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@app/lib/methods/helpers/ensureSecureProtocol.test.ts`:
- Around line 20-23: Add a new test to cover the combined scenario where a URL
has leading double slashes and internal double slashes: call
ensureSecureProtocol with the string '//www.google.com/docs//api' and assert it
returns 'https://www.google.com/docs//api' so the function both strips the
leading '//' and preserves internal '//' in the path; place this alongside the
existing tests in ensureSecureProtocol.test.ts and reference the
ensureSecureProtocol function.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 78f60f74-4ee8-4808-97d0-b24cbeea5123
📒 Files selected for processing (2)
app/lib/methods/helpers/ensureSecureProtocol.test.tsapp/lib/methods/helpers/ensureSecureProtocol.ts
📜 Review details
🔇 Additional comments (1)
app/lib/methods/helpers/ensureSecureProtocol.ts (1)
6-6: LGTM! The fix correctly addresses the bug.The regex anchor
^ensures that only leading//is stripped, preserving any//occurrences within the URL path. This is the correct minimal fix for the reported issue.
What this fixes
This PR fixes a bug in
ensureSecureProtocol.Before, when a URL had no protocol, the helper removed the first
//anywhere in the string.That worked for values like
//www.google.com, but it could also change//that was part of the path.Example:
www.google.com/docs//apiBefore:
https://www.google.com/docsapiAfter:
https://www.google.com/docs//apiWhat changed
I updated the helper to remove
//only when it is at the start of the value.I also added a test for a URL with
//inside the path, because that was the broken case.Types of changes
Checklist
Summary by CodeRabbit