mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
id/matrixuri: fix parsing url-encoded matrix URIs
This commit is contained in:
parent
788621f7e0
commit
8fb04d1806
2 changed files with 13 additions and 2 deletions
|
|
@ -210,7 +210,11 @@ func ProcessMatrixURI(uri *url.URL) (*MatrixURI, error) {
|
|||
if len(parts[1]) == 0 {
|
||||
return nil, ErrEmptySecondSegment
|
||||
}
|
||||
parsed.MXID1 = parts[1]
|
||||
var err error
|
||||
parsed.MXID1, err = url.PathUnescape(parts[1])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to url decode second segment %q: %w", parts[1], err)
|
||||
}
|
||||
|
||||
// Step 6: if the first part is a room and the URI has 4 segments, construct a second level identifier
|
||||
if parsed.Sigil1 == '!' && len(parts) == 4 {
|
||||
|
|
@ -226,7 +230,10 @@ func ProcessMatrixURI(uri *url.URL) (*MatrixURI, error) {
|
|||
if len(parts[3]) == 0 {
|
||||
return nil, ErrEmptyFourthSegment
|
||||
}
|
||||
parsed.MXID2 = parts[3]
|
||||
parsed.MXID2, err = url.PathUnescape(parts[3])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to url decode fourth segment %q: %w", parts[3], err)
|
||||
}
|
||||
}
|
||||
|
||||
// Step 7: parse the query and extract via and action items
|
||||
|
|
|
|||
|
|
@ -77,8 +77,12 @@ func TestParseMatrixURI_RoomID(t *testing.T) {
|
|||
parsedVia, err := id.ParseMatrixURI("matrix:roomid/7NdBVvkd4aLSbgKt9RXl:example.org?via=maunium.net&via=matrix.org")
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, parsedVia)
|
||||
parsedEncoded, err := id.ParseMatrixURI("matrix:roomid/7NdBVvkd4aLSbgKt9RXl%3Aexample.org")
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, parsedEncoded)
|
||||
|
||||
assert.Equal(t, roomIDLink, *parsed)
|
||||
assert.Equal(t, roomIDLink, *parsedEncoded)
|
||||
assert.Equal(t, roomIDViaLink, *parsedVia)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue