Skip to content

Commit

Permalink
Revert "pkg/obfuscate: improve formatting and string parsing in the S…
Browse files Browse the repository at this point in the history
…QL obfuscator (#11967)"

This reverts commit 8ab1d18.
  • Loading branch information
knusbaum committed Jan 5, 2023
1 parent 284f31c commit 7d39d92
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 157 deletions.
16 changes: 5 additions & 11 deletions pkg/obfuscate/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func (f *metadataFinderFilter) Filter(token, lastToken TokenKind, buffer []byte)
// SELECT ... FROM [tableName]
// DELETE FROM [tableName]
// ... JOIN [tableName]
if r, _ := utf8.DecodeRune(buffer); !unicode.IsLetter(r) && !strings.ContainsRune("\"'`", r) {
// first character in buffer is not a letter, nor a quote, meaning it is not an identifier;
// we might have a nested query like SELECT * FROM (SELECT ...)
if r, _ := utf8.DecodeRune(buffer); !unicode.IsLetter(r) {
// first character in buffer is not a letter; we might have a nested
// query like SELECT * FROM (SELECT ...)
break
}
fallthrough
Expand Down Expand Up @@ -381,8 +381,7 @@ func attemptObfuscation(tokenizer *SQLTokenizer) (*ObfuscatedQuery, error) {
if buff != nil {
if out.Len() != 0 {
switch token {
case '.', ']', ',':
// skip adding a space before dots, closing square brackets, and commas.
case ',':
case '=':
if lastToken == ':' {
// do not add a space before an equals if a colon was
Expand All @@ -391,12 +390,7 @@ func attemptObfuscation(tokenizer *SQLTokenizer) (*ObfuscatedQuery, error) {
}
fallthrough
default:
switch lastToken {
case '[', '.':
// skip adding a space after dots and opening square brackets.
default:
out.WriteRune(' ')
}
out.WriteRune(' ')
}
}
out.Write(buff)
Expand Down
Loading

0 comments on commit 7d39d92

Please sign in to comment.