mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-09-28 07:51:42 +01:00
Validate story body ranges against media story captions.
This commit is contained in:
+4
-1
@@ -414,7 +414,10 @@ object EnvelopeContentValidator {
|
||||
return Result.Invalid("[StoryMessage] Style body range is missing a start or length!")
|
||||
}
|
||||
|
||||
if (storyMessage.bodyRanges.hasInvalidBounds(storyMessage.textAttachment?.text)) {
|
||||
// Body ranges apply to the text of a text story, or to the caption of a media story.
|
||||
val storyText: String? = storyMessage.textAttachment?.text ?: storyMessage.fileAttachment?.caption
|
||||
|
||||
if (storyMessage.bodyRanges.hasInvalidBounds(storyText)) {
|
||||
return Result.Invalid("[StoryMessage] Body range with out-of-bounds start/length!")
|
||||
}
|
||||
|
||||
|
||||
+30
@@ -779,6 +779,36 @@ class EnvelopeContentValidatorTest {
|
||||
assert(result is EnvelopeContentValidator.Result.Valid)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `validate - ensure story body range within the bounds of the file attachment caption is marked valid`() {
|
||||
val content = Content(
|
||||
storyMessage = StoryMessage(
|
||||
fileAttachment = AttachmentPointer(cdnKey = "key", caption = "abc"),
|
||||
bodyRanges = listOf(
|
||||
BodyRange(start = 0, length = 3, style = BodyRange.Style.ITALIC)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val result = EnvelopeContentValidator.validate(Envelope(clientTimestamp = 1234), content, SELF_ACI, CiphertextMessage.WHISPER_TYPE)
|
||||
assert(result is EnvelopeContentValidator.Result.Valid)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `validate - ensure story body range extending past the end of the file attachment caption is marked invalid`() {
|
||||
val content = Content(
|
||||
storyMessage = StoryMessage(
|
||||
fileAttachment = AttachmentPointer(cdnKey = "key", caption = "abc"),
|
||||
bodyRanges = listOf(
|
||||
BodyRange(start = 2, length = 10, style = BodyRange.Style.ITALIC)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val result = EnvelopeContentValidator.validate(Envelope(clientTimestamp = 1234), content, SELF_ACI, CiphertextMessage.WHISPER_TYPE)
|
||||
assert(result is EnvelopeContentValidator.Result.Invalid)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `validate - ensure story context with a valid author but missing sentTimestamp is marked invalid`() {
|
||||
val content = Content(
|
||||
|
||||
Reference in New Issue
Block a user