Skip to content

Commit

Permalink
feat: fix link regexp bug
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpiotzh committed Jun 15, 2022
1 parent 0a17a6d commit fb152d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (d *DNSData) updateDNSRecord(contentRecord dao.TableRecordsInfo) (dao.Table
value := contentRecord.Value
// compatible with ipfs://xxx sia://xxx https://ipfs.io/ipfs/xxx
if contentRecord.Key == "skynet" || contentRecord.Key == "ipfs" {
re := regexp.MustCompile(`([0-9A-Za-z-]{46})`)
re := regexp.MustCompile(`([0-9A-Za-z-_]{46})`)
if results := re.FindStringSubmatch(value); len(results) == 2 {
value = results[1]
}
Expand Down
21 changes: 21 additions & 0 deletions example/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package example

import (
"fmt"
"regexp"
"testing"
)

func TestLink(t *testing.T) {
//value := "ipfs://PAIg0cuUJFfX7pBunqLLgQIaeTt8tEJtBIrPSzuxWkD3BA"
//value = "PAIg0cuUJFfX7pBunqLLgQIaeTt8tEJtBIrPSzuxWkD3BA"
//value = "https://siasky.net/PAIg0cuUJFfX7pBunqLLgQIaeTt8tEJtBIrPSzuxWkD3BA"
//value = "https://siasky.net/XAELj697T77MQOhB2XD-GGNY0bSel0xla9mS1p7L50bv6w"
value := "https://siasky.net/AAAEn_sRJSoC8N95In4b9E-n23C9udgTO-NkrrKGN4QDNg"
fmt.Println(len("AAAEn_sRJSoC8N95In4b9E-n23C9udgTO-NkrrKGN4QDNg"))
re := regexp.MustCompile(`([0-9A-Za-z-_]{46})`)
if results := re.FindStringSubmatch(value); len(results) == 2 {
value = results[1]
}
fmt.Println(value)
}

0 comments on commit fb152d3

Please sign in to comment.