Enforce `mediaIDRegex` to be only valid `mediaIDCharacters` (#1020)

Error messages indicate that:
> mediaId must be a non-empty string using only characters in `mediaIDCharacters`

However the regex used only required that some characters in the filename match
the restriction, not that the entire filename does. This commit ensures that
the filename must entirely fullfill the `mediaIDCharacters` restriction

Signed-off-by: Sid Karunaratne <sid@karunaratne.net>

Co-authored-by: Kegsay <kegan@matrix.org>
main
Sid Karunaratne 2020-05-13 19:04:54 +08:00 committed by GitHub
parent 106a335b7d
commit 31e6a7f193
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -43,7 +43,7 @@ import (
const mediaIDCharacters = "A-Za-z0-9_=-" const mediaIDCharacters = "A-Za-z0-9_=-"
// Note: unfortunately regex.MustCompile() cannot be assigned to a const // Note: unfortunately regex.MustCompile() cannot be assigned to a const
var mediaIDRegex = regexp.MustCompile("[" + mediaIDCharacters + "]+") var mediaIDRegex = regexp.MustCompile("^[" + mediaIDCharacters + "]+$")
// downloadRequest metadata included in or derivable from a download or thumbnail request // downloadRequest metadata included in or derivable from a download or thumbnail request
// https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-download-servername-mediaid // https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-download-servername-mediaid