Skip to content

Commit ac1a099

Browse files
fix: Update regex for flagged NFTs (#8161)
* fix: Update regex for flagged NFTs * improvements * typo * Update packages/shared/locales/en.json Co-authored-by: Begoña Álvarez de la Cruz <[email protected]> * fix --------- Co-authored-by: Begoña Álvarez de la Cruz <[email protected]>
1 parent 3d9ad5e commit ac1a099

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { localize } from '../../i18n'
12
import { INft } from '../interfaces'
23

34
/**
@@ -10,10 +11,13 @@ export function isFlaggedNft(nft: INft): string | undefined {
1011
const parsedMetadata = nft.parsedMetadata
1112
const parsedName = parsedMetadata?.name ?? ''
1213
const parsedDescription = parsedMetadata?.description ?? ''
13-
const urlRegex = /((https?|ftp|file):\/\/)?([\da-z-]+\.)+([a-z]{2,6})([/\w .-]*)*\/?$/gi
14+
const urlRegex = new RegExp(
15+
'\\b(?:https?:\\/\\/)?[a-zA-Z0-9-]+(?:[\\.\\u2024\\uFE52\\uFF0E\\uFF61][a-zA-Z0-9-]+)+\\b(?:[\\/\\?#][^\\s()<>]*)?',
16+
'i'
17+
)
1418
const containsUrl = urlRegex.test(name) || urlRegex.test(parsedName) || urlRegex.test(parsedDescription)
15-
// Note: in order to avoid issues with the translations, we are using a hardcoded string here
16-
const WARNING_MESSAGE =
17-
'Be careful when following unknown links. Never share your private keys, nor enter them into any websites or services. '
18-
return containsUrl ? WARNING_MESSAGE : undefined
19+
20+
if (containsUrl) {
21+
return localize('warning.nft.flagged')
22+
}
1923
}

packages/shared/locales/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,6 +2127,9 @@
21272127
},
21282128
"participation": {
21292129
"noFunds": "You do not have any IOTA."
2130+
},
2131+
"nft": {
2132+
"flagged": "Be careful when following unknown links. Never share your private keys, nor enter them into any websites or services."
21302133
}
21312134
},
21322135
"tooltips": {

0 commit comments

Comments
 (0)