MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / matchModelPattern

Function matchModelPattern

internal/toolinjection/injection.go:226–258  ·  view source on GitHub ↗

matchModelPattern performs simple wildcard matching where '*' matches zero or more characters.

(pattern, model string)

Source from the content-addressed store, hash-verified

224
225// matchModelPattern performs simple wildcard matching where '*' matches zero or more characters.
226func matchModelPattern(pattern, model string) bool {
227 pattern = strings.TrimSpace(pattern)
228 model = strings.TrimSpace(model)
229 if pattern == "" {
230 return false
231 }
232 if pattern == "*" {
233 return true
234 }
235 pi, si := 0, 0
236 starIdx := -1
237 matchIdx := 0
238 for si < len(model) {
239 if pi < len(pattern) && pattern[pi] == model[si] {
240 pi++
241 si++
242 } else if pi < len(pattern) && pattern[pi] == '*' {
243 starIdx = pi
244 matchIdx = si
245 pi++
246 } else if starIdx >= 0 {
247 pi = starIdx + 1
248 matchIdx++
249 si = matchIdx
250 } else {
251 return false
252 }
253 }
254 for pi < len(pattern) && pattern[pi] == '*' {
255 pi++
256 }
257 return pi == len(pattern)
258}
259
260// RemoveRuleByName removes the first rule with the given name from the slice
261// and returns the resulting slice. Used to delete a rule after it fires.

Callers 2

ShouldInjectFunction · 0.70
TestMatchModelPatternFunction · 0.70

Calls

no outgoing calls

Tested by 1

TestMatchModelPatternFunction · 0.56