Skip to content

Commit

Permalink
Hotfix: Allow url-fields to be empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarvelle committed Dec 21, 2023
1 parent f178b81 commit 68081a9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,9 @@ object TagValidator {
val domainRegex =
"https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)"

if (!field.validation.required && value.isEmpty) {
return None
}
if (value.matches(domainRegex)) {
if (field.validation.allowedDomains.isEmpty) None
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,31 @@ class EmbedTagValidatorTest extends UnitSuite {
TagValidator.validate("content", tag2).size should be(0)
}

test("validate should succeed if source url is not required and empty") {
val tag = generateTagWithAttrs(
Map(
TagAttribute.DataResource -> ResourceType.CampaignBlock.toString,
TagAttribute.DataTitle -> "Title",
TagAttribute.DataDescription -> "Description",
TagAttribute.DataHeadingLevel -> "h3"
)
)
TagValidator.validate("content", tag).size should be(0)

val tag2 = generateTagWithAttrs(
Map(
TagAttribute.DataResource -> ResourceType.CampaignBlock.toString,
TagAttribute.DataTitle -> "Title",
TagAttribute.DataDescription -> "Description",
TagAttribute.DataHeadingLevel -> "h3",
TagAttribute.DataUrl -> "",
TagAttribute.DataUrlText -> ""
)
)
TagValidator.validate("content", tag2).size should be(0)

}

test("validate should fail if source url is from an illlegal domain") {
val tag = generateTagWithAttrs(
Map(
Expand Down

0 comments on commit 68081a9

Please sign in to comment.