From 2812254ba55075632f526d1a7f683f57d660415d Mon Sep 17 00:00:00 2001 From: ssube Date: Wed, 13 Nov 2019 07:50:56 -0600 Subject: [PATCH] fix(config): accept S regex flag, anchor slashes --- src/config/type/Regexp.ts | 2 +- test/config/type/TestRegexp.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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); + }); });