Skip to content

Commit

Permalink
[ML] Align transform id validation with regexp used in ES code. (#98783
Browse files Browse the repository at this point in the history
…) (#98895)

Fixes isTransformIdValid() to use the same RegExp used in Elasticsearch's transform code.

Co-authored-by: Walter Rafelsberger <walter@elastic.co>
  • Loading branch information
kibanamachine and walterra authored Apr 30, 2021
1 parent 0f5204f commit 70547de
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions x-pack/plugins/transform/public/app/common/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import { Subscription } from 'rxjs';

import { TransformId } from '../../../common/types/transform';

// Transform name must contain lowercase alphanumeric (a-z and 0-9), hyphens or underscores;
// It must also start and end with an alphanumeric character.
// Via https://github.com/elastic/elasticsearch/blob/master/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/utils/TransformStrings.java#L24
// Matches a string that contains lowercase characters, digits, hyphens, underscores or dots.
// The string may start and end only in characters or digits.
// Note that '.' is allowed but not documented.
export function isTransformIdValid(transformId: TransformId) {
return /^[a-z0-9\-\_]+$/g.test(transformId) && !/^([_-].*)?(.*[_-])?$/g.test(transformId);
return /^[a-z0-9](?:[a-z0-9_\-\.]*[a-z0-9])?$/g.test(transformId);
}

export enum REFRESH_TRANSFORM_LIST_STATE {
Expand Down

0 comments on commit 70547de

Please sign in to comment.