From ccac8fd0d65cf1e5f773bea85ffafa830cdad3b4 Mon Sep 17 00:00:00 2001 From: Anshu S Panda Date: Sun, 31 May 2020 22:12:45 +0530 Subject: [PATCH] fix(isSlug): fix to disallow spaces (#1338) * Fix: Space Error in isSlug() * Added Space Test for isSlug() --- src/lib/isSlug.js | 2 +- test/validators.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/isSlug.js b/src/lib/isSlug.js index bb1b290bb..da0193137 100644 --- a/src/lib/isSlug.js +++ b/src/lib/isSlug.js @@ -1,6 +1,6 @@ import assertString from './util/assertString'; -let charsetRegex = /^[^-_](?!.*?[-_]{2,})([a-z0-9\\-]{1,}).*[^-_]$/; +let charsetRegex = /^[^\s-_](?!.*?[-_]{2,})([a-z0-9-\\]{1,})[^\s]*[^-_\s]$/; export default function isSlug(str) { assertString(str); diff --git a/test/validators.js b/test/validators.js index 0caf824fd..a842e71d9 100755 --- a/test/validators.js +++ b/test/validators.js @@ -8369,6 +8369,7 @@ describe('Validators', () => { 'not-slug-', '_not-slug', 'not-slug_', + 'not slug', ], }); });