Bugfix - Enforce URL length check in LinkMetadata before attempting to insert to database (#29589)

* Add missing URL length validation in LinkMetadata

* Added MaxURLLength constant

* Add test to validate new URL length limit

* Add comment about table constraint

* Use a seperate error string for URL length errors

* Added error string fpr URL length

* Updated error message

* Update en.json

* Fixed gofmt error in link_metadata.go

* use right txn id

```release-note
NONE
```

---------

Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Nadav Tasher
2025-01-08 16:32:39 +02:00
коммит произвёл GitHub
родитель e6b4764e0d
Коммит baf9bf82c9
3 изменённых файлов: 19 добавлений и 0 удалений

Просмотреть файл

@@ -146,6 +146,16 @@ func TestLinkMetadataIsValid(t *testing.T) {
},
Expected: false,
},
{
Name: "should be invalid because of URL length being too long",
Metadata: &LinkMetadata{
URL: "http://example.com/?" + strings.Repeat("a", 2048),
Timestamp: 1546300800000,
Type: LinkMetadataTypeImage,
Data: &PostImage{},
},
Expected: false,
},
} {
t.Run(test.Name, func(t *testing.T) {
appErr := test.Metadata.IsValid()