Strip leading @ from password reset input
This commit is contained in:
7
app/soapbox/utils/__tests__/input.test.ts
Normal file
7
app/soapbox/utils/__tests__/input.test.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { normalizeUsername } from '../input';
|
||||
|
||||
test('normalizeUsername', () => {
|
||||
expect(normalizeUsername('@alex')).toBe('alex');
|
||||
expect(normalizeUsername('alex@alexgleason.me')).toBe('alex@alexgleason.me');
|
||||
expect(normalizeUsername('@alex@gleasonator.com')).toBe('alex@gleasonator.com');
|
||||
});
|
||||
13
app/soapbox/utils/input.ts
Normal file
13
app/soapbox/utils/input.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/** Trim the username and strip the leading @. */
|
||||
const normalizeUsername = (username: string): string => {
|
||||
const trimmed = username.trim();
|
||||
if (trimmed[0] === '@') {
|
||||
return trimmed.slice(1);
|
||||
} else {
|
||||
return trimmed;
|
||||
}
|
||||
};
|
||||
|
||||
export {
|
||||
normalizeUsername,
|
||||
};
|
||||
Reference in New Issue
Block a user