fix(@desktop/Profile): validate social links before saving #7926

This commit is contained in:
mprakhov 2022-11-10 22:49:49 +02:00 committed by Mykhailo Prakhov
parent cb4380582e
commit 0114334763
2 changed files with 16 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import json, random, times, strutils, os
import json, random, times, strutils, os, re, chronicles
import nimcrypto
import signing_phrases
@ -51,3 +51,11 @@ proc defaultDataDir(): string =
else:
targetDir
absolutePath(joinPath(parentDir, "Status"))
proc validateLink*(link: string): bool =
result = true
if link.len() != 0:
if not match(
link, re"[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)", 0):
error "Invalid social link", errDescription = link
result = false

View File

@ -1,8 +1,9 @@
import NimQml, chronicles, json, strutils, sequtils, tables, sugar
import NimQml, chronicles, json, strutils, sequtils
import ../../common/[network_constants]
import ../../common/types as common_types
import ../../common/social_links
import ../../common/utils as common_utils
import ../../../app/core/eventemitter
import ../../../app/core/fleets/fleet_configuration
import ../../../app/core/signals/types
@ -834,6 +835,11 @@ QtObject:
proc setSocialLinks*(self: Service, links: SocialLinks): bool =
result = false
let isValid = all(links, proc (link: SocialLink): bool = common_utils.validateLink(link.url))
if (not isValid):
error "error saving social links"
return result
try:
let response = status_settings.setSocialLinks(%*links)