From 2f5526ddbac5b89bc831fc2e75312f7d7ff9779b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauris=20Buk=C5=A1is-Haberkorns?= Date: Mon, 5 Aug 2019 14:38:40 +0300 Subject: [PATCH] Improve detection of unsupported regexp syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lauris Bukšis-Haberkorns --- internal/code-generator/generator/heuristics.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/code-generator/generator/heuristics.go b/internal/code-generator/generator/heuristics.go index 67a9c0c..a49ad87 100644 --- a/internal/code-generator/generator/heuristics.go +++ b/internal/code-generator/generator/heuristics.go @@ -160,11 +160,12 @@ func parseYaml(file string) (*Heuristics, error) { // isUnsupportedRegexpSyntax filters regexp syntax that is not supported by RE2. // In particular, we stumbled up on usage of next cases: +// - lookbehind & lookahead // - named & numbered capturing group/after text matching // - backreference // For referece on supported syntax see https://github.com/google/re2/wiki/Syntax func isUnsupportedRegexpSyntax(reg string) bool { - return strings.Contains(reg, `(?<`) || strings.Contains(reg, `\1`) || + return strings.Contains(reg, `(?<`) || strings.Contains(reg, `(?=`) || strings.Contains(reg, `\1`) || // See https://github.com/github/linguist/pull/4243#discussion_r246105067 (strings.HasPrefix(reg, multilinePrefix+`/`) && strings.HasSuffix(reg, `/`)) }