Improve detection of unsupported regexp syntax

Signed-off-by: Lauris Bukšis-Haberkorns <lauris@nix.lv>
This commit is contained in:
Lauris Bukšis-Haberkorns 2019-08-05 14:38:40 +03:00
parent ee9d089406
commit 2f5526ddba
No known key found for this signature in database
GPG Key ID: DFDE60A0093EB926

View File

@ -160,11 +160,12 @@ func parseYaml(file string) (*Heuristics, error) {
// isUnsupportedRegexpSyntax filters regexp syntax that is not supported by RE2. // isUnsupportedRegexpSyntax filters regexp syntax that is not supported by RE2.
// In particular, we stumbled up on usage of next cases: // In particular, we stumbled up on usage of next cases:
// - lookbehind & lookahead
// - named & numbered capturing group/after text matching // - named & numbered capturing group/after text matching
// - backreference // - backreference
// For referece on supported syntax see https://github.com/google/re2/wiki/Syntax // For referece on supported syntax see https://github.com/google/re2/wiki/Syntax
func isUnsupportedRegexpSyntax(reg string) bool { 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 // See https://github.com/github/linguist/pull/4243#discussion_r246105067
(strings.HasPrefix(reg, multilinePrefix+`/`) && strings.HasSuffix(reg, `/`)) (strings.HasPrefix(reg, multilinePrefix+`/`) && strings.HasSuffix(reg, `/`))
} }