Skip to content

OpenStock is an open-source alternative to expensive market platforms. Track real-time prices, set personalized alerts, and explore detailed company insights — built openly, for everyone, forever free.

fix(email): keep <strong> balanced, check country against the picker's list

ravixalgorithmc94c96181c65
diff --git a/__tests__/welcome-email.test.ts b/__tests__/welcome-email.test.ts
index 4a4b0af..40b7e7e 100644
--- a/__tests__/welcome-email.test.ts
+++ b/__tests__/welcome-email.test.ts
@@ -23,6 +23,6 @@ describe('sendWelcomeEmail', () => {
expect(html).not.toContain('<img src=x');
expect(html).not.toContain('onclick');
expect(html).toContain('&lt;a href=&quot;https://evil.example&quot;&gt;Click&lt;/a&gt; $&#39; $&amp;');
- expect(html).toContain('Hi <strong>growth</strong> fan. Verify your accountbold</strong> R&amp;D</p>');
+ expect(html).toContain('Hi <strong>growth</strong> fan. Verify your account<strong>bold</strong> R&amp;D</p>');
});
});
diff --git a/lib/actions/auth.actions.ts b/lib/actions/auth.actions.ts
index a0cc221..bc600cf 100644
--- a/lib/actions/auth.actions.ts
+++ b/lib/actions/auth.actions.ts
@@ -4,13 +4,15 @@ import { auth } from "@/lib/better-auth/auth";
import { inngest } from "@/lib/inngest/client";
import { headers } from "next/headers";
import { INVESTMENT_GOALS, PREFERRED_INDUSTRIES, RISK_TOLERANCE_OPTIONS } from "@/lib/constants";
+import countryList from "react-select-country-list";
const isOption = (options: readonly { value: string }[], value: unknown) => options.some((o) => o.value === value);
+const COUNTRY_CODES = new Set(countryList().getValues()); // the same list the sign-up country picker shows
export const signUpWithEmail = async ({ email, password, fullName, country, investmentGoals, riskTolerance, preferredIndustry }: SignUpFormData) => {
// These fields go into the AI prompt for the welcome email, so only accept the form's own values
if (typeof fullName !== 'string' || !fullName.trim() || fullName.length > 80
- || typeof country !== 'string' || !/^[A-Z]{2}$/.test(country)
+ || typeof country !== 'string' || !COUNTRY_CODES.has(country)
|| !isOption(INVESTMENT_GOALS, investmentGoals)
|| !isOption(RISK_TOLERANCE_OPTIONS, riskTolerance)
|| !isOption(PREFERRED_INDUSTRIES, preferredIndustry)) {
diff --git a/lib/utils.ts b/lib/utils.ts
index b71a4f5..b096888 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -272,6 +272,7 @@ export const escapeHtml = (value: string) =>
// Keep its text and plain <strong>, drop every other tag (links, images, styles), and wrap it ourselves.
export const sanitizeEmailIntro = (html: string) => {
const text = html
+ .replace(/<strong\b[^>]*>/gi, '<strong>') // keep the emphasis balanced, drop its attributes
.replace(/<(?!\/?strong>)[^>]*>/gi, '')
.replace(/&nbsp;/g, ' ').replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&')
.trim();