chat: validate chat names

Add a regex check for non-lowercase, non-slash, non-hyphen characters,
or numerals, and a quick check for starts-with-slashes, double-slashes,
to a boolean before creating a chat at that path.
This commit is contained in:
Matilde Park 2019-12-18 00:10:22 -05:00
parent a64e516fc5
commit e2cfcafc92
3 changed files with 12 additions and 4 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -77,7 +77,15 @@ export class NewScreen extends Component {
onClickCreate() {
const { props, state } = this;
if (!state.idName) {
let invalidChara = new RegExp(/[^a-z0-9/-]/);
let invalid = (
(!state.idName) || (state.idName.startsWith("/")) ||
(state.idName.includes("//")) || (invalidChara.test(state.idName))
);
if (invalid) {
this.setState({
idError: true,
inviteError: false
@ -192,7 +200,7 @@ export class NewScreen extends Component {
<div className="w-100">
<p className="f8 mt3 lh-copy db">Chat Name</p>
<p className="f9 gray2 db mb4">
Alphanumeric characters, dashes, and slashes only
Lowercase alphanumeric characters, dashes, and slashes only
</p>
<textarea
className="f7 ba b--gray3 pa3 db w-100"