mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-17 17:19:02 +00:00
fix(@desktop/Profile): validate social links before saving #7926
This commit is contained in:
parent
cb4380582e
commit
0114334763
@ -1,4 +1,4 @@
|
|||||||
import json, random, times, strutils, os
|
import json, random, times, strutils, os, re, chronicles
|
||||||
import nimcrypto
|
import nimcrypto
|
||||||
import signing_phrases
|
import signing_phrases
|
||||||
|
|
||||||
@ -51,3 +51,11 @@ proc defaultDataDir(): string =
|
|||||||
else:
|
else:
|
||||||
targetDir
|
targetDir
|
||||||
absolutePath(joinPath(parentDir, "Status"))
|
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
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import NimQml, chronicles, json, strutils, sequtils, tables, sugar
|
import NimQml, chronicles, json, strutils, sequtils
|
||||||
|
|
||||||
import ../../common/[network_constants]
|
import ../../common/[network_constants]
|
||||||
import ../../common/types as common_types
|
import ../../common/types as common_types
|
||||||
import ../../common/social_links
|
import ../../common/social_links
|
||||||
|
import ../../common/utils as common_utils
|
||||||
import ../../../app/core/eventemitter
|
import ../../../app/core/eventemitter
|
||||||
import ../../../app/core/fleets/fleet_configuration
|
import ../../../app/core/fleets/fleet_configuration
|
||||||
import ../../../app/core/signals/types
|
import ../../../app/core/signals/types
|
||||||
@ -834,6 +835,11 @@ QtObject:
|
|||||||
|
|
||||||
proc setSocialLinks*(self: Service, links: SocialLinks): bool =
|
proc setSocialLinks*(self: Service, links: SocialLinks): bool =
|
||||||
result = false
|
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:
|
try:
|
||||||
let response = status_settings.setSocialLinks(%*links)
|
let response = status_settings.setSocialLinks(%*links)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user