Alanxtl commented on code in PR #3416:
URL: https://github.com/apache/dubbo-go/pull/3416#discussion_r3409372740


##########
protocol/triple/triple_protocol/protocol.go:
##########
@@ -367,3 +379,41 @@ func canonicalizeContentTypeSlow(contentType string) 
string {
        }
        return mime.FormatMediaType(base, params)
 }
+
+// isSimpleMediaType reports whether s is a well-formed, already-lowercase 
media
+// type without parameters: letters a-z, '.', '+', '-', exactly one '/'.
+func isSimpleMediaType(s string) bool {
+       slashes := 0
+       for i := 0; i < len(s); i++ {
+               c := s[i]
+               switch {
+               case c >= 'a' && c <= 'z':
+               case c == '.' || c == '+' || c == '-':
+               case c == '/':
+                       slashes++
+               default:
+                       return false
+               }
+       }
+       return slashes == 1
+}

Review Comment:
   I think the new charset fast path should make `isSimpleMediaType` stricter 
before using it for the parameterized case. Right now it only checks that there 
is exactly one `/`, so malformed bases like `"/; charset=UTF-8"` or 
`"application/; charset=UTF-8"` take the fast path and get rewritten to 
lowercase charset. The previous slow path would call `mime.ParseMediaType`, 
fail, and return the original string unchanged. Since the PR intends malformed 
input to fall through unchanged, can we require both sides of `/` to be 
non-empty before accepting the fast path?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to