Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dialect/sql: escape special characters in pattern matching #2062

Merged
merged 1 commit into from Oct 24, 2021

Conversation

a8m
Copy link
Member

@a8m a8m commented Oct 24, 2021

b.WriteByte(w[i])
}
return b.String(), true
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another approach is to store indexes of special characters, and then loop over the indexes, use copy and inject escape characters between them. Something as follows:

b := make([]byte, 0, len(w) + len(idx))
for _, idx := range idxs {
	b = append(b, w[:idx]...)
	w = [idx+1:]
	b = append(b, '//')
}
b = append(b, w...)

Need to check what is faster.

@a8m a8m force-pushed the escape/pattern-matching branch 2 times, most recently from 3a8bb89 to 825e2f0 Compare October 24, 2021 18:03
@a8m a8m merged commit a1f6de2 into master Oct 24, 2021
@a8m a8m deleted the escape/pattern-matching branch October 24, 2021 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: LIKE-based predicates should escape input
1 participant