@@ -146,13 +146,19 @@ func canonicaliseComponent(component string, params *httpsfv.Params, message *Me
146146 if ! message .IsRequest && ! isReq {
147147 return nil , errors .New ("path component not valid for responses" )
148148 }
149- return httpsfv .NewItem (message .URL .Path ), nil
149+ // empty path means use `/`
150+ path := message .URL .Path
151+ if path == "" || path [0 ] != '/' {
152+ path = "/" + path
153+ }
154+ return httpsfv .NewItem (path ), nil
150155 case "@query" :
151156 // Section 2.2.7 covers canonicalisation of the query.
152157 // https://www.ietf.org/archive/id/draft-ietf-httpbis-message-signatures-19.html#name-query
153158 if ! message .IsRequest && ! isReq {
154159 return nil , errors .New ("query component not valid for responses" )
155160 }
161+ // absent query params means use `?`
156162 return httpsfv .NewItem ("?" + message .URL .RawQuery ), nil
157163 case "@query-param" :
158164 // Section 2.2.8 covers canonicalisation of the query-param.
@@ -167,10 +173,19 @@ func canonicaliseComponent(component string, params *httpsfv.Params, message *Me
167173 if ! ok {
168174 return nil , errors .New ("query-param must have a named parameter" )
169175 }
170- if ! message .URL .Query ().Has (name .(string )) {
176+ decodedName , err := url .QueryUnescape (name .(string ))
177+ if err != nil {
178+ return nil , fmt .Errorf ("unable to decode query parameter name: %w" , err )
179+ }
180+ query := message .URL .Query ()
181+ if ! query .Has (decodedName ) {
171182 return nil , fmt .Errorf ("expected query parameter \" %s\" not found" , name )
172183 }
173- return httpsfv .NewItem (message .URL .Query ().Get (name .(string ))), nil
184+ decodedValue , err := url .QueryUnescape (query .Get (decodedName ))
185+ if err != nil {
186+ return nil , fmt .Errorf ("unable to decode query parameter value: %w" , err )
187+ }
188+ return httpsfv .NewItem (url .QueryEscape (decodedValue )), nil
174189 case "@status" :
175190 // Section 2.2.9 covers canonicalisation of the status.
176191 // https://www.ietf.org/archive/id/draft-ietf-httpbis-message-signatures-19.html#name-status-code
0 commit comments