@@ -47,18 +47,6 @@ func parseErrNotFoundWithFallbackToError(msg error) error {
47
47
return msg
48
48
}
49
49
50
- // Use a string to move it into RODATA
51
- // print("".join("\\x01" if chr(i) not in string.ascii_letters + string.digits else "\\x00" for i in range(ord('z')+1)))
52
- const notAsciiLetterOrDigitsLUT = "\x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x01 \x01 \x01 \x01 \x01 \x01 \x01 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x01 \x01 \x01 \x01 \x01 \x01 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 "
53
-
54
- func notAsciiLetterOrDigits (r rune ) bool {
55
- if r > 'z' {
56
- return true
57
- }
58
-
59
- return notAsciiLetterOrDigitsLUT [r ] > 0
60
- }
61
-
62
50
//lint:ignore ST1008 this function is not using the error as a mean to return failure but it massages it to return the correct type
63
51
func parseErrNotFound (msg string ) (error , bool ) {
64
52
if msg == "" {
@@ -76,6 +64,12 @@ func parseErrNotFound(msg string) (error, bool) {
76
64
return nil , false
77
65
}
78
66
67
+ // Assume CIDs break on:
68
+ // - Whitespaces: " \t\n\r\v\f"
69
+ // - Semicolon: ";" this is to parse ipld.ErrNotFound wrapped in multierr
70
+ // - Double Quotes: "\"" this is for parsing %q and %#v formating
71
+ const cidBreakSet = " \t \n \r \v \f ;\" "
72
+
79
73
//lint:ignore ST1008 using error as values
80
74
func parseIPLDErrNotFound (msg string ) (error , bool ) {
81
75
// The patern we search for is:
@@ -99,9 +93,9 @@ func parseIPLDErrNotFound(msg string) (error, bool) {
99
93
c = cid .Undef
100
94
postIndex = len ("node" )
101
95
} else {
102
- // Assume that CIDs only contain a-zA-Z0-9 characters.
103
- // This is true because go-ipld-format use go-cid#Cid.String which use base{3{2,6},58}.
104
- postIndex = strings . IndexFunc ( msgPostKey , notAsciiLetterOrDigits )
96
+ postIndex = strings . IndexFunc ( msgPostKey , func ( r rune ) bool {
97
+ return strings . ContainsAny ( string ( r ), cidBreakSet )
98
+ } )
105
99
if postIndex < 0 {
106
100
postIndex = len (msgPostKey )
107
101
}
0 commit comments