Skip to content

Commit

Permalink
fix: number rewrite when meet spec suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxsen committed Jan 29, 2025
1 parent 26f54e2 commit 0a9d9d1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
8 changes: 4 additions & 4 deletions config/sys_number_rule_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ var sysUncensorRule = []string{
var sysRewriteRule = []NumberRewriteRule{ //rewrite 逻辑在number.Parse之前, 所以数据可能存在小写的情况, 需要特殊处理
{
Remark: "format fc2",
Rule: `(?i)^fc2[-|_]?(ppv)?[-|_](\d+)$`,
Rewrite: `FC2-PPV-$2`,
Rule: `(?i)^fc2[-|_]?(ppv)?[-|_](\d+)([-|_].*)?$`, //需要处理后面的-C-CD1之类的字符串, 用正则出来起来真的麻烦...
Rewrite: `FC2-PPV-$2$3`,
},
{
Remark: "format number like '234abc-123' to 'abc-123'",
Rule: `^\d+([a-zA-Z]+[-|_]\d+)$`,
Rewrite: `$1`,
Rule: `^\d+([a-zA-Z]+[-|_]\d+)([-|_].*)?$`,
Rewrite: `$1$2`,
},
}

Expand Down
26 changes: 23 additions & 3 deletions config/sys_number_rule_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ func TestFc2Rewrit(t *testing.T) {
in: "fc2-ppv-12345",
out: "FC2-PPV-12345",
},
{
in: "fc2ppv-12345-CD1",
out: "FC2-PPV-12345-CD1",
},
{
in: "fc2ppv-12345-C-CD1",
out: "FC2-PPV-12345-C-CD1",
},
{
in: "fc2ppv-123-asdasqwe2",
out: "FC2-PPV-123-asdasqwe2",
},
{
in: "fc2",
out: "fc2",
Expand All @@ -71,6 +83,10 @@ func TestFc2Rewrit(t *testing.T) {
in: "fc2-12345",
out: "FC2-PPV-12345",
},
{
in: "fc2-123445-cd1",
out: "FC2-PPV-123445-cd1",
},
{
in: "fc2ppv-123",
out: "FC2-PPV-123",
Expand Down Expand Up @@ -109,17 +125,21 @@ func TestNumberAlphaNumberRewrite(t *testing.T) {
out: "aaa-123434",
},
{
in: "aaa-1234",
out: "aaa-1234",
in: "aaa-1234-CD1",
out: "aaa-1234-CD1",
},
{
in: "222aaa-22222_helloworld",
out: "222aaa-22222_helloworld",
out: "aaa-22222_helloworld",
},
{
in: "123abc_1234",
out: "abc_1234",
},
{
in: "123abc_123aaa",
out: "123abc_123aaa",
},
}
rewriter := ruleapi.NewRegexpRewriter()
for _, item := range sysNumberRule.NumberRewriteRules {
Expand Down

0 comments on commit 0a9d9d1

Please sign in to comment.