Strip only the enclosing quotes when parsing visibility query string values - #12019
Open
Dev-next-gen wants to merge 1 commit into
Open
Dev-next-gen wants to merge 1 commit into
Dev-next-gen wants to merge 1 commit into
Conversation
ParseValue used strings.Trim(sqlValue, "'") to unquote string values, which removes every leading and trailing single quote, not just the pair that delimits the literal. A visibility query such as Keyword01 = '''foo''' (value 'foo') was converted to a filter on foo by every store, since the unified and legacy query converters both rebuild the literal from expr.Val and pass it through ParseValue. Reuse ExtractStringValue, which strips exactly one pair.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed?
sqlquery.ParseValuenow unquotes string literals withExtractStringValue, which drops exactly the enclosing pair of single quotes. It usedstrings.Trim(sqlValue, "'"), which drops every leading and trailing quote.Why?
I was reading the visibility query converter and noticed that
parseSQLVal(in the unified converter and in the legacy SQL one) rebuilds the literal as'%s'fromexpr.Valand hands it toParseValue. Because of theTrim, a value that itself starts or ends with a quote loses it.Keyword01 = '''foo'''is a query for the value'foo', but every store ends up filtering onfoo:In the same way,
WorkflowId = 'abc'''matchesabcinstead ofabc', so the query returns executions the caller didn't ask for and misses the one it did. Quotes in the middle of a value ('foo''s bar') were already handled correctly, which is why the existing test case didn't catch this.How did you test it?
I added three cases to
TestConvertSqlValueand one to the sharedqueryConverterTestCases, which runs against the MySQL, PostgreSQL, SQLite and Elasticsearch converters (the legacy converter tests pick it up as well). Without the fix, all four stores fail as shown above. With it,go test -tags test_dep ./common/sqlquery/ ./common/persistence/visibility/... ./common/archiver/... ./service/history/workflow/matcher/...passes.Potential risks
If
ParseValuegets a lone', it used to return an empty string and now rejects it as an unparsable value. None of the callers can produce that input: the converters always wrapexpr.Valin a pair of quotes, andsqlparser.Stringnever emits a bare quote.The legacy Elasticsearch converter (used only when
system.visibilityEnableUnifiedQueryConverteris off) goes throughsqlparser.String, which escapes quotes MySQL-style, so'foo''s bar'comes out asfoo\'s barthere. That's the same before and after this change, and I didn't touch it.AI tools used