-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Fix bad-weather-link & minor i18n change for bad-weather-text #208
Conversation
WalkthroughThe changes in this pull request involve updates to the Changes
Possibly related PRs
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
src/components/layout/BadWeatherCard.tsx
(1 hunks)src/i18n/translation.js
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- src/i18n/translation.js
🔇 Additional comments (1)
src/components/layout/BadWeatherCard.tsx (1)
27-27
: Verify the translation key exists
Let's ensure the new translation key "bad-weather-link" exists and returns a valid URL.
✅ Verification successful
Translation key exists with valid URLs for both English and Traditional Chinese
The translation key "bad-weather-link" is properly defined in src/i18n/translation.js
with valid URLs for both English (/en/
) and Traditional Chinese (/tc/
) versions pointing to the Transport Department's special news page.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if the translation key exists and contains a valid URL
# Search for the translation key definition
echo "Searching for bad-weather-link translation key:"
rg -A 1 '"bad-weather-link"' src/
# Search for any usage of this key to ensure consistency
echo -e "\nChecking all usages of the key:"
rg 'bad-weather-link'
Length of output: 1074
@@ -24,7 +24,7 @@ const BadWeatherCard = () => { | |||
<Paper | |||
variant="outlined" | |||
sx={rootSx} | |||
onClick={() => window.open(t("bad-weather-text"), "_target")} | |||
onClick={() => window.open(t("bad-weather-link"), "_target")} |
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.
Fix security vulnerabilities in external link handling
The current implementation has several security and UX issues:
- Using "_target" is incorrect (should be "_blank")
- Missing security attributes for external links
- No URL validation before opening
Apply this fix:
-onClick={() => window.open(t("bad-weather-link"), "_target")}
+onClick={() => {
+ const url = t("bad-weather-link");
+ if (url && /^https?:\/\//.test(url)) {
+ window.open(url, "_blank", "noopener,noreferrer");
+ }
+}}
📝 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.
onClick={() => window.open(t("bad-weather-link"), "_target")} | |
onClick={() => { | |
const url = t("bad-weather-link"); | |
if (url && /^https?:\/\//.test(url)) { | |
window.open(url, "_blank", "noopener,noreferrer"); | |
} | |
}} |
Before:
The bad weather alert links to
https://hkbus.app/公共交通及班次或受惡劣天氣影響,以下資料未必反映最新狀況。按此查看官方公佈。 or
https://hkbus.app/Services may be impacted by bad weather. Data displayed below might not be accurate. Check here to see official announcements.
Summary by CodeRabbit
New Features
Bug Fixes