Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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 force-pushed the escape/pattern-matching branch from 825e2f0 to 735e5f5 Compare October 24, 2021 18:04
@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

2 participants