From 25483bb6cc9e03cf6dd770dfc16d02593d2ccd76 Mon Sep 17 00:00:00 2001 From: Cole Eason Date: Tue, 10 Sep 2024 13:36:27 -0400 Subject: [PATCH] Fix redirects 1. Removes redirects containing anchors 2. Updates verifyRedirects.sh to check for anchors and cleans up errors in the code. 3. Updates comments in createHelpDirects. --- .github/scripts/createHelpRedirects.sh | 2 +- .github/scripts/verifyRedirect.sh | 28 +++++++++++++++----------- docs/redirects.csv | 9 +++------ 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.github/scripts/createHelpRedirects.sh b/.github/scripts/createHelpRedirects.sh index 1425939ff3ec..76696977de4d 100755 --- a/.github/scripts/createHelpRedirects.sh +++ b/.github/scripts/createHelpRedirects.sh @@ -1,7 +1,7 @@ #!/bin/bash # # Adds new routes to the Cloudflare Bulk Redirects list for communityDot to helpDot -# pages. Does some basic sanity checking. +# pages. Sanity checking is done upstream in the PRs themselves in verifyRedirect.sh. set -e diff --git a/.github/scripts/verifyRedirect.sh b/.github/scripts/verifyRedirect.sh index 05c402ad7766..af9861f40921 100755 --- a/.github/scripts/verifyRedirect.sh +++ b/.github/scripts/verifyRedirect.sh @@ -1,27 +1,31 @@ #!/bin/bash -# HelpDot - Verifies that redirects.csv does not have any duplicates -# Duplicate sourceURLs break redirection on cloudflare pages +# HelpDot - Verifies that redirects.csv does not have any errors that would prevent +# the bulk redirects in Cloudflare from working. This includes: +# Duplicate sourceURLs +# Source URLs containing anchors or URL params +# URLs pointing to themselves +# +# We also prevent adding source or destination URLs outside of an allowed list +# of domains. That's because these redirects run on our zone as a whole, so you +# could add a redirect for sites outside of help/community and Cloudflare would allow it +# and it would work. source scripts/shellUtils.sh declare -r REDIRECTS_FILE="docs/redirects.csv" declare -a ITEMS_TO_ADD -declare -r RED='\033[0;31m' -declare -r GREEN='\033[0;32m' -declare -r NC='\033[0m' - duplicates=$(awk -F, 'a[$1]++{print $1}' $REDIRECTS_FILE) if [[ -n "$duplicates" ]]; then - echo "${RED}duplicate redirects are not allowed: $duplicates ${NC}" + echo "${RED}duplicate redirects are not allowed: $duplicates ${RESET}" exit 1 fi npm run detectRedirectCycle DETECT_CYCLE_EXIT_CODE=$? if [[ DETECT_CYCLE_EXIT_CODE -eq 1 ]]; then - echo -e "${RED}The redirects.csv has a cycle. Please remove the redirect cycle because it will cause an infinite redirect loop ${NC}" + echo -e "${RED}The redirects.csv has a cycle. Please remove the redirect cycle because it will cause an infinite redirect loop ${RESET}" exit 1 fi @@ -46,8 +50,8 @@ while read -r line; do # Basic sanity checking to make sure that the source and destination are in expected # subdomains. - if ! [[ $SOURCE_URL =~ ^https://(community|help)\.expensify\.com ]] || [[ $SOURCE_URL =~ \# ]]; then - error "Found source URL that is not a communityDot or helpDot URL, or contains a '#': $SOURCE_URL" + if ! [[ $SOURCE_URL =~ ^https://(community|help)\.expensify\.com ]] || [[ $SOURCE_URL =~ (\#|\?) ]]; then + error "Found source URL that is not a communityDot or helpDot URL, or contains a '#' or '?': $SOURCE_URL" exit 1 fi @@ -66,9 +70,9 @@ done <<< "$(tail +2 $REDIRECTS_FILE)" # Sanity check that we should actually be running this and we aren't about to delete # every single redirect. if [[ "${#ITEMS_TO_ADD[@]}" -lt 1 ]]; then - error "No items found to add, why are we running?" + error "${RED}No items found to add, why are we running?${RESET}" exit 1 fi -echo -e "${GREEN}The redirects.csv is valid!${NC}" +echo -e "${GREEN}The redirects.csv is valid!${RESET}" exit 0 diff --git a/docs/redirects.csv b/docs/redirects.csv index 4d90785956fe..a60b6babcb31 100644 --- a/docs/redirects.csv +++ b/docs/redirects.csv @@ -542,9 +542,9 @@ https://community.expensify.com/discussion/8118/how-to-redeem-deel-com-perk,http https://community.expensify.com/discussion/8256/how-to-redeem-25-off-slack-with-the-expensify-card,https://help.expensify.com/articles/expensify-classic/expensify-card/Expensify-Card-Perks#slack https://community.expensify.com/discussion/8737/exclusive-perks-for-expensify-card-members,https://help.expensify.com/articles/expensify-classic/expensify-card/Expensify-Card-Perks https://community.expensify.com/discussion/9040/how-to-redeem-10-off-netsuite-with-the-expensify-card,https://help.expensify.com/articles/expensify-classic/expensify-card/Expensify-Card-Perks#netsuite -https://community.expensify.com/discussion/4828/how-to-match-your-company-cards-statement-to-expensify/p1?new=1,https://help.expensify.com/articles/expensify-classic/connect-credit-cards/company-cards/Reconciliation +https://community.expensify.com/discussion/4828/how-to-match-your-company-cards-statement-to-expensify,https://help.expensify.com/articles/expensify-classic/connect-credit-cards/company-cards/Reconciliation https://community.expensify.com/discussion/5580/deep-dive-configure-advanced-settings-for-netsuite/,https://help.expensify.com/articles/expensify-classic/connections/netsuite/Configure-Netsuite#step-3-configure-advanced-settings -https://community.expensify.com/discussion/7231/how-to-export-invoices-to-netsuite/p1?new=1,https://help.expensify.com/articles/expensify-classic/connections/netsuite/Configure-Netsuite#export-invoices +https://community.expensify.com/discussion/7231/how-to-export-invoices-to-netsuite/,https://help.expensify.com/articles/expensify-classic/connections/netsuite/Configure-Netsuite#export-invoices https://community.expensify.com/discussion/9168/how-to-troubleshoot-general-errors-when-uploading-your-id-via-onfido,https://help.expensify.com/articles/new-expensify/expenses-&-payments/Resolve-Errors-Adding-a-Bank-Account https://community.expensify.com/discussion/4707/how-to-set-up-your-mobile-app/,https://use.expensify.com/expensify-mobile-app https://community.expensify.com/discussion/7066/introducing-concierge-travel,https://help.expensify.com/expensify-classic/hubs/travel/ @@ -554,7 +554,6 @@ https://help.expensify.com/articles/expensify-classic/expensify-card/Set-Up-the- https://community.expensify.com/discussion/5542/deep-dive-what-are-ereceipts,https://help.expensify.com/articles/expensify-classic/workspaces/Expense-Settings#ereceipts https://community.expensify.com/discussion/5738/deep-dive-how-does-concierge-receipt-audit-work,https://help.expensify.com/articles/expensify-classic/workspaces/Expense-Settings#concierge-receipt-audit https://community.expensify.com/discussion/4643/how-to-invite-people-to-your-policy-using-a-join-link,https://help.expensify.com/articles/expensify-classic/workspaces/Invite-members-and-assign-roles#invite-with-a-link -https://community.expensify.com/discussion/4975/how-to-invite-users-to-your-policy-manually-or-in-bulk/p1?new=1,https://help.expensify.com/articles/expensify-classic/workspaces/Invite-members-and-assign-roles https://help.expensify.com/articles/expensify-classic/workspaces/Invoicing,https://help.expensify.com/articles/expensify-classic/workspaces/Set-Up-Invoicing https://help.expensify.com/articles/expensify-classic/bank-accounts-and-payments/bank-accounts/Enable-Global-Reimbursements.md,https://help.expensify.com/articles/expensify-classic/bank-accounts-and-payments/bank-accounts/Enable-Global-Reimbursements https://help.expensify.com/articles/expensify-classic/integrations/travel-integrations/Trip-Actions,https://help.expensify.com/expensify-classic/hubs/connections/ @@ -565,8 +564,6 @@ https://help.expensify.com/articles/expensify-classic/bank-accounts-and-payments https://help.expensify.com/articles/expensify-classic/connect-credit-cards/Global-Reimbursements,https://help.expensify.com/articles/expensify-classic/bank-accounts-and-payments/bank-accounts/Enable-Global-Reimbursements https://community.expensify.com/discussion/4641/how-to-add-a-deposit-only-bank-account-both-personal-and-business,https://help.expensify.com/articles/expensify-classic/bank-accounts-and-payments/bank-accounts/Connect-US-Business-Bank-Account https://community.expensify.com/discussion/5940/how-to-get-reimbursed-outside-the-us-with-wise-for-non-us-employees,https://help.expensify.com/articles/expensify-classic/bank-accounts-and-payments/Third-Party-Payments -https://community.expensify.com/home/leaving?allowTrusted=1&target=https%3A%2F%2Fqbo.intuit.com%2Fapp%2Fvendors,https://help.expensify.com/articles/expensify-classic/connections/quickbooks-online/Quickbooks-Online-Troubleshooting -https://community.expensify.com/discussion/5654/deep-dive-using-expense-rules-to-vendor-match-when-exporting-to-an-accounting-package/p1?new=1,https://help.expensify.com/articles/expensify-classic/connections/xero/Xero-Troubleshooting -https://help.expensify.com/articles/expensify-classic/spending-insights/(https://help.expensify.com/articles/expensify-classic/spending-insights/Custom-Templates),https://help.expensify.com/articles/expensify-classic/spending-insights/Custom-Templates +https://help.expensify.com/articles/expensify-classic/spending-insights,https://help.expensify.com/articles/expensify-classic/spending-insights/Custom-Templates https://help.expensify.com/articles/expensify-classic/settings/account-settings/Set-notifications,https://help.expensify.com/articles/expensify-classic/settings/account-settings/Set-Notifications https://help.expensify.com/articles/expensify-classic/bank-accounts-and-payments/payments/Reimburse-Reports-Invoices-and-Bills,https://help.expensify.com/articles/expensify-classic/bank-accounts-and-payments/payments/Reimburse-Reports