diff --git a/src/config/type/Regexp.ts b/src/config/type/Regexp.ts index 47f2317..6879556 100644 --- a/src/config/type/Regexp.ts +++ b/src/config/type/Regexp.ts @@ -3,7 +3,7 @@ import { isNil } from 'lodash'; import { InvalidArgumentError } from '../../error/InvalidArgumentError'; -export const REGEXP_REGEXP = /\/(.*)\/([gimuy]*)/; +export const REGEXP_REGEXP = /^\/(.+)\/([gimsuy]*)$/; export const regexpType = new YamlType('!regexp', { kind: 'scalar', diff --git a/test/config/type/TestRegexp.ts b/test/config/type/TestRegexp.ts index 9720197..d7c998c 100644 --- a/test/config/type/TestRegexp.ts +++ b/test/config/type/TestRegexp.ts @@ -16,4 +16,12 @@ describeLeaks('regexp config type', async () => { itLeaks('should not match bare strings', async () => { expect(regexpType.resolve('foo')).to.equal(false); }); + + itLeaks('should not match invalid flags', async () => { + expect(regexpType.resolve('/foo/notrealflags')).to.equal(false); + }); + + itLeaks('should not match regex embedded in a longer string', async () => { + expect(regexpType.resolve('some/regex/with-padding')).to.equal(false); + }); });