mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2025-12-28 21:38:18 +00:00
Escpae prefix and namespace when creating regex
This commit is contained in:
parent
0b58042494
commit
999339635f
1 changed files with 8 additions and 4 deletions
|
|
@ -62,11 +62,15 @@ export class DefaultTagFormatter implements TagFormatter {
|
||||||
};
|
};
|
||||||
|
|
||||||
public IsValid(tag: string): boolean {
|
public IsValid(tag: string): boolean {
|
||||||
|
const regexEscape = (literal: string) => literal.replace(/\W/g, '\\$&');
|
||||||
|
const tagPrefix = regexEscape(this.tagPrefix);
|
||||||
|
const namespaceSeperator = regexEscape(this.namespaceSeperator);
|
||||||
|
const namespace = regexEscape(this.namespace);
|
||||||
|
|
||||||
if (!!this.namespace) {
|
if (!!this.namespace) {
|
||||||
return new RegExp(`^${this.tagPrefix}[0-9]+\.[0-9]+\.[0-9]+${this.namespaceSeperator}${this.namespace}$`).test(tag);
|
return new RegExp(`^${tagPrefix}[0-9]+\.[0-9]+\.[0-9]+${namespaceSeperator}${namespace}$`).test(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RegExp(`^${this.tagPrefix}[0-9]+\.[0-9]+\.[0-9]+$`).test(tag);
|
return new RegExp(`^${tagPrefix}[0-9]+\.[0-9]+\.[0-9]+$`).test(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue