Skip to content

Issues with Regular expressions parsed in insights- Where strings with quotes/parens were used

Created by: amberfurbush0317

Sourcegraph version: Reproduced on 3.41 and Sourcegraph.com

Platform information: Reproduced on demo.sourcegraph.com, Sourcegraph.com, and self-hosted customer instance (docker-compose)

Steps to reproduce:

  1. Create a graph for code search below query. Before (broken):

("# OR fromHex: OR rgb( OR .hex(" OR .init(red: OR UIColor(red: OR UIColor. ) count:all -file:\.json -file:Test file:\.swift patterntype:literal

  1. the corresponding query created above from one of the graphs will still works in code search, but if you click “Create Insight”, the result is broken.

  2. In order to fix the graphs it was found that the parser used by Insights appears to break things.

After (fixed) version of the original query:

-file:\.json -file:Test file:\.swift (content:("#) OR content:(fromHex:) OR content:(rgb\() OR content:(\.hex\(") OR content:(\.init\(red:) OR content(UIColor\(red:) OR content:(UIColor\.)) count:all patterntype:regexp

The queries that had things like content:"SOME_REGEXP_HERE"`` patterntype:regexp orpatterntype:literalwhere strings with quotes/parens were used had been broken. Instead, you have to use patterntype:regexp for everything and using parens around the whole value instead of quotes, eg. content:(SOME_REGEXP_HERE)

Expected behavior:

The prior version would allow strings with quotes/parens (parenthesis) were used in the expression which would cause no issues with the insight graph.

Actual behavior:

Strings with quotes/parens (parenthesis) cannot be used with the expressions or would break the Insights graph