Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
🎨 Increased allowed lengths of tag names/slugs and user names (#905)
Browse files Browse the repository at this point in the history
refs TryGhost/Ghost#8143

Increases existing input validation length (soft limits) of the following fields:
   - `tags.name`: 191 chars
   - `tags.slug`: 191 chars
   - `users.name`: 191 chars
  • Loading branch information
aileen authored and kevinansfield committed Nov 9, 2017
1 parent 8bb24e1 commit d7cd0e9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions app/validators/tag-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ export default BaseValidator.create({
} else if (name.match(/^,/)) {
model.get('errors').add('name', 'Tag names can\'t start with commas.');
this.invalidate();
} else if (!validator.isLength(name, 0, 150)) {
model.get('errors').add('name', 'Tag names cannot be longer than 150 characters.');
} else if (!validator.isLength(name, 0, 191)) {
model.get('errors').add('name', 'Tag names cannot be longer than 191 characters.');
this.invalidate();
}
},

slug(model) {
let slug = model.get('slug');

if (!validator.isLength(slug, 0, 150)) {
model.get('errors').add('slug', 'URL cannot be longer than 150 characters.');
if (!validator.isLength(slug, 0, 191)) {
model.get('errors').add('slug', 'URL cannot be longer than 191 characters.');
this.invalidate();
}
},
Expand Down
2 changes: 1 addition & 1 deletion app/validators/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default PasswordValidator.create({
if (validator.empty(name)) {
model.get('errors').add('name', 'Please enter a name.');
this.invalidate();
} else if (!validator.isLength(name, 0, 150)) {
} else if (!validator.isLength(name, 0, 191)) {
model.get('errors').add('name', 'Name is too long');
this.invalidate();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/team-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ describe('Acceptance: Team', function () {
expect(find('.user-details-bottom .first-form-group').hasClass('error'), 'username input is in error state with blank input').to.be.true;

// test too long user name
await fillIn('[data-test-name-input]', new Array(160).join('a'));
await fillIn('[data-test-name-input]', new Array(195).join('a'));
await triggerEvent('[data-test-name-input]', 'blur');

expect(find('.user-details-bottom .first-form-group').hasClass('error'), 'username input is in error state with too long input').to.be.true;
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/validators/tag-settings-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ describe('Unit: Validator: tag-settings', function () {

it('passes with valid name', function () {
// longest valid name
let tag = Tag.create({name: (new Array(151).join('x'))});
let tag = Tag.create({name: (new Array(192).join('x'))});
let passed = false;

expect(tag.get('name').length, 'name length').to.equal(150);
expect(tag.get('name').length, 'name length').to.equal(191);

run(() => {
tag.validate({property: 'name'}).then(() => {
Expand Down Expand Up @@ -116,11 +116,11 @@ describe('Unit: Validator: tag-settings', function () {

it('validates name length', function () {
// shortest invalid name
let tag = Tag.create({name: (new Array(152).join('x'))});
let tag = Tag.create({name: (new Array(193).join('x'))});
let passed = false;
let nameErrors;

expect(tag.get('name').length, 'name length').to.equal(151);
expect(tag.get('name').length, 'name length').to.equal(192);

run(() => {
tag.validate({property: 'name'}).then(() => {
Expand All @@ -130,18 +130,18 @@ describe('Unit: Validator: tag-settings', function () {

nameErrors = tag.get('errors').errorsFor('name')[0];
expect(nameErrors.attribute, 'errors.name.attribute').to.equal('name');
expect(nameErrors.message, 'errors.name.message').to.equal('Tag names cannot be longer than 150 characters.');
expect(nameErrors.message, 'errors.name.message').to.equal('Tag names cannot be longer than 191 characters.');

expect(passed, 'passed').to.be.false;
expect(tag.get('hasValidated'), 'hasValidated').to.include('name');
});

it('passes with valid slug', function () {
// longest valid slug
let tag = Tag.create({slug: (new Array(151).join('x'))});
let tag = Tag.create({slug: (new Array(192).join('x'))});
let passed = false;

expect(tag.get('slug').length, 'slug length').to.equal(150);
expect(tag.get('slug').length, 'slug length').to.equal(191);

run(() => {
tag.validate({property: 'slug'}).then(() => {
Expand All @@ -155,11 +155,11 @@ describe('Unit: Validator: tag-settings', function () {

it('validates slug length', function () {
// shortest invalid slug
let tag = Tag.create({slug: (new Array(152).join('x'))});
let tag = Tag.create({slug: (new Array(193).join('x'))});
let passed = false;
let slugErrors;

expect(tag.get('slug').length, 'slug length').to.equal(151);
expect(tag.get('slug').length, 'slug length').to.equal(192);

run(() => {
tag.validate({property: 'slug'}).then(() => {
Expand All @@ -169,18 +169,18 @@ describe('Unit: Validator: tag-settings', function () {

slugErrors = tag.get('errors').errorsFor('slug')[0];
expect(slugErrors.attribute, 'errors.slug.attribute').to.equal('slug');
expect(slugErrors.message, 'errors.slug.message').to.equal('URL cannot be longer than 150 characters.');
expect(slugErrors.message, 'errors.slug.message').to.equal('URL cannot be longer than 191 characters.');

expect(passed, 'passed').to.be.false;
expect(tag.get('hasValidated'), 'hasValidated').to.include('slug');
});

it('passes with a valid description', function () {
// longest valid description
let tag = Tag.create({description: (new Array(201).join('x'))});
let tag = Tag.create({description: (new Array(501).join('x'))});
let passed = false;

expect(tag.get('description').length, 'description length').to.equal(200);
expect(tag.get('description').length, 'description length').to.equal(500);

run(() => {
tag.validate({property: 'description'}).then(() => {
Expand Down

0 comments on commit d7cd0e9

Please sign in to comment.