Fix: Do not allow white space around IP

Feat: Trim input on submit

Test: Add test for whitespace regex match
This commit is contained in:
Nelson Chan 2023-01-20 06:33:45 +08:00
parent ce82ad1c12
commit 95c934e08b
3 changed files with 20 additions and 4 deletions

View file

@ -9,7 +9,11 @@ describe("Test util-frontend.js", () => {
expect(regex.test("www.test.com")).to.be.true;
expect(regex.test("127.0.0.1")).to.be.true;
expect(regex.test("192.168.1.156")).to.be.true;
expect(regex.test(" 192.168.1.145")).to.be.false;
expect(regex.test("192.168.1.145 ")).to.be.false;
expect(regex.test(" fe80::3282:3ff:ae28:592")).to.be.false;
expect(regex.test("fe80::3282:3ff:ae28:592 ")).to.be.false;
["mqtt", "mqtts", "ws", "wss"].forEach(schema => {
expect(regex.test(`${schema}://www.test.com`)).to.be.false;
expect(regex.test(`${schema}://127.0.0.1`)).to.be.false;
@ -23,11 +27,15 @@ describe("Test util-frontend.js", () => {
expect(regex.test("www.test.com")).to.be.true;
expect(regex.test("127.0.0.1")).to.be.true;
expect(regex.test("192.168.1.156")).to.be.true;
expect(regex.test(" 192.168.1.145")).to.be.false;
expect(regex.test("192.168.1.145 ")).to.be.false;
expect(regex.test(" fe80::3282:3ff:ae28:592")).to.be.false;
expect(regex.test("fe80::3282:3ff:ae28:592 ")).to.be.false;
["mqtt", "mqtts", "ws", "wss"].forEach(schema => {
expect(regex.test(`${schema}://www.test.com`)).to.be.true;
expect(regex.test(`${schema}://127.0.0.1`)).to.be.true;
});
});
});
});
});