From 95623e60aef31f3a5325b92f21f79745c37b736a Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Fri, 4 Sep 2015 18:29:15 +0100 Subject: [PATCH] Add underscores to general validation fixes #5816 - general slugs and other fields should permit underscores as well as dashes --- core/server/api/utils.js | 2 +- core/test/unit/api_utils_spec.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/server/api/utils.js b/core/server/api/utils.js index f9e6ce5c72..bbe4d28a39 100644 --- a/core/server/api/utils.js +++ b/core/server/api/utils.js @@ -126,7 +126,7 @@ utils = { errors = errors.concat(validation.validate(value, key, globalValidations[key])); } else { // all other keys should be an alphanumeric string + -, like slug, tag, author, status, etc - errors = errors.concat(validation.validate(value, key, {matches: /^[a-z0-9\-]+$/})); + errors = errors.concat(validation.validate(value, key, {matches: /^[a-z0-9\-_]+$/})); } } }); diff --git a/core/test/unit/api_utils_spec.js b/core/test/unit/api_utils_spec.js index b6b5af0415..05f5ea0174 100644 --- a/core/test/unit/api_utils_spec.js +++ b/core/test/unit/api_utils_spec.js @@ -217,9 +217,9 @@ describe('API Utils', function () { check('limit', valid, invalid); }); - it('can validate `slug` or `status` or `author` etc as a-z, 0-9 and -', function () { - valid = ['hello-world', 'hello', '1-2-3', 1, '-1', -1]; - invalid = ['hello_world', '!things', '?other-things', 'thing"', '`ticks`']; + it('can validate `slug` or `status` or `author` etc as a-z, 0-9, - and _', function () { + valid = ['hello-world', 'hello', '1-2-3', 1, '-1', -1, 'hello_world']; + invalid = ['hello~world', '!things', '?other-things', 'thing"', '`ticks`']; check('slug', valid, invalid); check('status', valid, invalid);