MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / testUnescape

Function testUnescape

internal/re/regexp_test.go:213–263  ·  view source on GitHub ↗
(t *testing.T, v string)

Source from the content-addressed store, hash-verified

211}
212
213func testUnescape(t *testing.T, v string) string {
214 // replace urlencoded characters
215 var unescapeChars = [][2]string{
216 {`\s`, `(\s|%09|%0A|\+)`},
217 {`\(`, `(\(|%28)`},
218 {`=`, `(=|%3D)`},
219 {`<`, `(<|%3C)`},
220 {`\*`, `(\*|%2A)`},
221 {`\\`, `(\\|%2F)`},
222 {`!`, `(!|%21)`},
223 {`/`, `(/|%2F)`},
224 {`;`, `(;|%3B)`},
225 {`\+`, `(\+|%20)`},
226 }
227
228 for _, c := range unescapeChars {
229 if !strings.Contains(v, c[0]) {
230 continue
231 }
232 var pieces = strings.Split(v, c[0])
233
234 // 修复piece中错误的\
235 for pieceIndex, piece := range pieces {
236 var l = len(piece)
237 if l == 0 {
238 continue
239 }
240 if piece[l-1] != '\\' {
241 continue
242 }
243
244 // 计算\的数量
245 var countBackSlashes = 0
246 for i := l - 1; i >= 0; i-- {
247 if piece[i] == '\\' {
248 countBackSlashes++
249 } else {
250 break
251 }
252 }
253 if countBackSlashes%2 == 1 {
254 // 去掉最后一个
255 pieces[pieceIndex] = piece[:len(piece)-1]
256 }
257 }
258
259 v = strings.Join(pieces, c[1])
260 }
261
262 return v
263}

Callers 2

TestRegexp_SpecialFunction · 0.85
TestRegexp_Special2Function · 0.85

Calls 1

ContainsMethod · 0.45

Tested by

no test coverage detected