Skip to content
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

Allow non-ASCII email domains in Chrome #2402

Merged
merged 7 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"mui-language-picker": "^1.2.7",
"notistack": "^3.0.1",
"nspell": "^2.1.5",
"punycode": "^2.3.0",
"react": "^17.0.2",
"react-beautiful-dnd": "^13.1.1",
"react-chartjs-2": "^5.2.0",
Expand Down
11 changes: 7 additions & 4 deletions src/components/Login/SignUpPage/SignUpComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import {
meetsUsernameRequirements,
} from "utilities/utilities";

// Chrome silently converts non-ASCII characters in a Textfield of type="email".
// Use punycode.toUnicode() to convert them from punycode back to Unicode.
const punycode = require("punycode/");

const idAffix = "signUp";

interface SignUpDispatchProps {
Expand Down Expand Up @@ -111,9 +115,8 @@ export class SignUp extends React.Component<SignUpProps, SignUpState> {
}
}

async checkEmail(username: string) {
const emailTaken = await isEmailTaken(username);
if (emailTaken) {
async checkEmail(email: string) {
if (await isEmailTaken(punycode.toUnicode(email))) {
this.setState((prevState) => ({
error: { ...prevState.error, email: true },
}));
Expand All @@ -124,7 +127,7 @@ export class SignUp extends React.Component<SignUpProps, SignUpState> {
e.preventDefault();
const name = this.state.name.trim();
const username = this.state.username.trim();
const email = this.state.email.trim();
const email = punycode.toUnicode(this.state.email.trim());
const password = this.state.password.trim();
const confirmPassword = this.state.confirmPassword.trim();

Expand Down
20 changes: 6 additions & 14 deletions src/components/PasswordReset/tests/ResetPage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import "@testing-library/jest-dom";
import {
act,
cleanup,
render,
RenderOptions,
screen,
} from "@testing-library/react";
import { act, cleanup, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { ReactElement } from "react";
import { ReactElement, ReactNode } from "react";
import { Provider } from "react-redux";
import { MemoryRouter, Route, Routes } from "react-router-dom";
import configureMockStore from "redux-mock-store";

import "tests/reactI18nextMock";

import PasswordReset, {
PasswordResetTestIds,
} from "components/PasswordReset/ResetPage";
Expand Down Expand Up @@ -43,7 +38,7 @@ afterEach(cleanup);
const ResetPageProviders = ({
children,
}: {
children: React.ReactNode;
children: ReactNode;
}): ReactElement => {
return (
<Provider store={mockStore}>
Expand All @@ -56,12 +51,9 @@ const ResetPageProviders = ({
);
};

const customRender = async (
ui: ReactElement,
options?: Omit<RenderOptions, "wrapper">
): Promise<void> => {
const customRender = async (ui: ReactElement): Promise<void> => {
await act(async () => {
render(ui, { wrapper: ResetPageProviders, ...options });
render(ui, { wrapper: ResetPageProviders });
});
};

Expand Down
Loading