Remove tag name validation (#88800)

* Remove tag name validation

* remove i18n key

* add FTR test on searching for tag with special chars in name
This commit is contained in:
Pierre Gayvallet 2021-01-25 15:29:10 +01:00 committed by GitHub
parent 77851e8382
commit 93c46f5dfc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 79 additions and 23 deletions

View file

@ -37,8 +37,7 @@ Create a tag to assign to your saved objects.
image::images/tags/create-tag.png[Tag creation popin] image::images/tags/create-tag.png[Tag creation popin]
. Enter a name and select a color for the new tag. . Enter a name and select a color for the new tag.
+ +
The name can include alphanumeric characters (English letters and digits), `:`, `-`, `_` and the space character, The name cannot be longer than 50 characters.
and cannot be longer than 50 characters.
. Click *Create tag*. . Click *Create tag*.
[float] [float]

View file

@ -20,10 +20,8 @@ describe('Tag attributes validation', () => {
); );
}); });
it('returns an error message if the name contains invalid characters', () => { it('does not return an error message if the name contains special characters', () => {
expect(validateTagName('t^ag+name&')).toMatchInlineSnapshot( expect(validateTagName('t^ag+name&')).toBeUndefined();
`"Tag name can only include a-z, 0-9, _, -,:."`
);
}); });
}); });

View file

@ -12,7 +12,6 @@ export const tagNameMaxLength = 50;
export const tagDescriptionMaxLength = 100; export const tagDescriptionMaxLength = 100;
const hexColorRegexp = /^#[0-9A-F]{6}$/i; const hexColorRegexp = /^#[0-9A-F]{6}$/i;
const nameValidCharsRegexp = /^[0-9A-Z:\-_\s]+$/i;
export interface TagValidation { export interface TagValidation {
valid: boolean; valid: boolean;
@ -49,11 +48,6 @@ export const validateTagName = (name: string): string | undefined => {
}, },
}); });
} }
if (!nameValidCharsRegexp.test(name)) {
return i18n.translate('xpack.savedObjectsTagging.validation.name.errorInvalidCharacters', {
defaultMessage: 'Tag name can only include a-z, 0-9, _, -,:.',
});
}
}; };
export const validateTagDescription = (description: string): string | undefined => { export const validateTagDescription = (description: string): string | undefined => {

View file

@ -16633,7 +16633,6 @@
"xpack.savedObjectsTagging.uiApi.table.columnTagsName": "タグ", "xpack.savedObjectsTagging.uiApi.table.columnTagsName": "タグ",
"xpack.savedObjectsTagging.validation.color.errorInvalid": "タグ色は有効な 16 進数値色でなければなりません", "xpack.savedObjectsTagging.validation.color.errorInvalid": "タグ色は有効な 16 進数値色でなければなりません",
"xpack.savedObjectsTagging.validation.description.errorTooLong": "タグ説明は {length} 文字以下で入力してください", "xpack.savedObjectsTagging.validation.description.errorTooLong": "タグ説明は {length} 文字以下で入力してください",
"xpack.savedObjectsTagging.validation.name.errorInvalidCharacters": "タグ名には、a-z、0-9、-、: のみを使用できます。",
"xpack.savedObjectsTagging.validation.name.errorTooLong": "タグ名は {length} 文字以下で入力してください", "xpack.savedObjectsTagging.validation.name.errorTooLong": "タグ名は {length} 文字以下で入力してください",
"xpack.savedObjectsTagging.validation.name.errorTooShort": "タグ名は {length} 文字以上で入力してください", "xpack.savedObjectsTagging.validation.name.errorTooShort": "タグ名は {length} 文字以上で入力してください",
"xpack.searchProfiler.advanceTimeDescription": "イテレーターを次のドキュメントに進めるためにかかった時間。", "xpack.searchProfiler.advanceTimeDescription": "イテレーターを次のドキュメントに進めるためにかかった時間。",

View file

@ -16675,7 +16675,6 @@
"xpack.savedObjectsTagging.uiApi.table.columnTagsName": "标签", "xpack.savedObjectsTagging.uiApi.table.columnTagsName": "标签",
"xpack.savedObjectsTagging.validation.color.errorInvalid": "标签颜色必须为有效的十六进制颜色", "xpack.savedObjectsTagging.validation.color.errorInvalid": "标签颜色必须为有效的十六进制颜色",
"xpack.savedObjectsTagging.validation.description.errorTooLong": "标签描述不能超过 {length} 个字符。", "xpack.savedObjectsTagging.validation.description.errorTooLong": "标签描述不能超过 {length} 个字符。",
"xpack.savedObjectsTagging.validation.name.errorInvalidCharacters": "标签名称只能包含 a-z、0-9、_、-、:。",
"xpack.savedObjectsTagging.validation.name.errorTooLong": "标签名称不能超过 {length} 个字符", "xpack.savedObjectsTagging.validation.name.errorTooLong": "标签名称不能超过 {length} 个字符",
"xpack.savedObjectsTagging.validation.name.errorTooShort": "标签名称必须至少有 {length} 个字符", "xpack.savedObjectsTagging.validation.name.errorTooShort": "标签名称必须至少有 {length} 个字符",
"xpack.searchProfiler.advanceTimeDescription": "将迭代器推进至下一文档所用时间。", "xpack.searchProfiler.advanceTimeDescription": "将迭代器推进至下一文档所用时间。",

View file

@ -88,6 +88,24 @@
} }
} }
{
"type": "doc",
"value": {
"id": "tag:tag-special-chars",
"index": ".kibana",
"source": {
"tag": {
"name": "my%tag",
"description": "Special chars",
"color": "#AA0077"
},
"type": "tag",
"updated_at": "2017-09-21T18:49:16.270Z"
},
"type": "doc"
}
}
{ {
"type": "doc", "type": "doc",
"value": { "value": {
@ -356,3 +374,41 @@
} }
} }
} }
{
"type": "doc",
"value": {
"id": "dashboard:ref-to-tag-special-chars",
"index": ".kibana",
"source": {
"dashboard": {
"title": "dashboard 4 (tag-special-chars)",
"description": "",
"hits": 0,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"query\":{\"query\":\"\",\"language\":\"lucene\"},\"filter\":[{\"meta\":{\"negate\":false,\"disabled\":false,\"alias\":null,\"type\":\"phrase\",\"key\":\"animal\",\"value\":\"dog\",\"params\":{\"query\":\"dog\",\"type\":\"phrase\"},\"indexRefName\":\"kibanaSavedObjectMeta.searchSourceJSON.filter[0].meta.index\"},\"query\":{\"match\":{\"animal\":{\"query\":\"dog\",\"type\":\"phrase\"}}},\"$state\":{\"store\":\"appState\"}}],\"highlightAll\":true,\"version\":true}"
},
"optionsJSON": "{\"darkTheme\":false,\"useMargins\":true,\"hidePanelTitles\":false}",
"panelsJSON": "[]",
"timeFrom": "Mon Apr 09 2018 17:56:08 GMT-0400",
"timeRestore": true,
"timeTo": "Wed Apr 11 2018 17:56:08 GMT-0400",
"version": 1
},
"migrationVersion": {
"dashboard": "7.3.0"
},
"references": [
{
"id": "tag-special-chars",
"name": "tag-special-ref",
"type": "tag"
}
],
"type": "dashboard",
"updated_at": "2018-04-11T21:57:52.253Z"
}
}
}

View file

@ -8,7 +8,7 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context'; import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ getPageObjects, getService }: FtrProviderContext) { export default function ({ getPageObjects, getService }: FtrProviderContext) {
describe('GlobalSearchBar', function () { describe('TOTO GlobalSearchBar', function () {
const { common, navigationalSearch } = getPageObjects(['common', 'navigationalSearch']); const { common, navigationalSearch } = getPageObjects(['common', 'navigationalSearch']);
const esArchiver = getService('esArchiver'); const esArchiver = getService('esArchiver');
const browser = getService('browser'); const browser = getService('browser');
@ -61,6 +61,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
'dashboard 1 (tag-2)', 'dashboard 1 (tag-2)',
'dashboard 2 (tag-3)', 'dashboard 2 (tag-3)',
'dashboard 3 (tag-1 and tag-3)', 'dashboard 3 (tag-1 and tag-3)',
'dashboard 4 (tag-special-chars)',
]); ]);
}); });
it('shows a suggestion when searching for a term matching a tag name', async () => { it('shows a suggestion when searching for a term matching a tag name', async () => {
@ -94,6 +95,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
'dashboard 1 (tag-2)', 'dashboard 1 (tag-2)',
'dashboard 2 (tag-3)', 'dashboard 2 (tag-3)',
'dashboard 3 (tag-1 and tag-3)', 'dashboard 3 (tag-1 and tag-3)',
'dashboard 4 (tag-special-chars)',
]); ]);
}); });
@ -111,6 +113,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
'dashboard 1 (tag-2)', 'dashboard 1 (tag-2)',
'dashboard 2 (tag-3)', 'dashboard 2 (tag-3)',
'dashboard 3 (tag-1 and tag-3)', 'dashboard 3 (tag-1 and tag-3)',
'dashboard 4 (tag-special-chars)',
]); ]);
}); });
@ -181,6 +184,14 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
expect(results.map((result) => result.label)).to.eql(['My awesome vis (tag-4)']); expect(results.map((result) => result.label)).to.eql(['My awesome vis (tag-4)']);
}); });
it('allows to filter by tags containing special characters', async () => {
await navigationalSearch.searchFor('tag:"my%tag"');
const results = await navigationalSearch.getDisplayedResults();
expect(results.map((result) => result.label)).to.eql(['dashboard 4 (tag-special-chars)']);
});
it('returns no results when searching for an unknown tag', async () => { it('returns no results when searching for an unknown tag', async () => {
await navigationalSearch.searchFor('tag:unknown'); await navigationalSearch.searchFor('tag:unknown');

View file

@ -60,7 +60,7 @@ export default function ({ getService }: FtrProviderContext) {
await supertest await supertest
.post(`/api/saved_objects_tagging/tags/create`) .post(`/api/saved_objects_tagging/tags/create`)
.send({ .send({
name: 'Inv%li& t@g n*me', name: 'a',
description: 'some desc', description: 'some desc',
color: 'this is not a valid color', color: 'this is not a valid color',
}) })
@ -74,7 +74,7 @@ export default function ({ getService }: FtrProviderContext) {
valid: false, valid: false,
warnings: [], warnings: [],
errors: { errors: {
name: 'Tag name can only include a-z, 0-9, _, -,:.', name: 'Tag name must be at least 2 characters',
color: 'Tag color must be a valid hex color', color: 'Tag color must be a valid hex color',
}, },
}, },

View file

@ -78,7 +78,7 @@ export default function ({ getService }: FtrProviderContext) {
await supertest await supertest
.post(`/api/saved_objects_tagging/tags/tag-1`) .post(`/api/saved_objects_tagging/tags/tag-1`)
.send({ .send({
name: 'Inv%li& t@g n*me', name: 'a',
description: 'some desc', description: 'some desc',
color: 'this is not a valid color', color: 'this is not a valid color',
}) })
@ -92,7 +92,7 @@ export default function ({ getService }: FtrProviderContext) {
valid: false, valid: false,
warnings: [], warnings: [],
errors: { errors: {
name: 'Tag name can only include a-z, 0-9, _, -,:.', name: 'Tag name must be at least 2 characters',
color: 'Tag color must be a valid hex color', color: 'Tag color must be a valid hex color',
}, },
}, },

View file

@ -54,7 +54,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await tagModal.openCreate(); await tagModal.openCreate();
await tagModal.fillForm( await tagModal.fillForm(
{ {
name: 'invalid&$%name', name: 'a',
description: 'The name will fails validation', description: 'The name will fails validation',
color: '#FF00CC', color: '#FF00CC',
}, },
@ -73,7 +73,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await tagModal.openCreate(); await tagModal.openCreate();
await tagModal.fillForm( await tagModal.fillForm(
{ {
name: 'invalid&$%name', name: 'a',
description: 'The name will fails validation', description: 'The name will fails validation',
color: '#FF00CC', color: '#FF00CC',
}, },

View file

@ -71,7 +71,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await tagModal.openEdit('tag-2'); await tagModal.openEdit('tag-2');
await tagModal.fillForm( await tagModal.fillForm(
{ {
name: 'invalid&$%name', name: 'a',
}, },
{ submit: true } { submit: true }
); );
@ -88,7 +88,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await tagModal.openEdit('tag-2'); await tagModal.openEdit('tag-2');
await tagModal.fillForm( await tagModal.fillForm(
{ {
name: 'invalid&$%name', name: 'a',
description: 'edited description', description: 'edited description',
color: '#FF00CC', color: '#FF00CC',
}, },