Skip to content

Commit e0c73a7

Browse files
authored
refactor: add u flag to all regex (#12229)
Co-authored-by: Jack-Works <Jack-Works@users.noreply.github.com>
1 parent 910f35f commit e0c73a7

File tree

145 files changed

+296
-297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+296
-297
lines changed

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const avoidMistakeRules = {
107107
'@typescript-eslint/no-wrapper-object-types': 'error',
108108
/// Unicode support
109109
'no-misleading-character-class': 'error', // RegEx
110-
// 'require-unicode-regexp': 'error', // RegEx modern RegEx with Unicode support
110+
'require-unicode-regexp': 'error', // RegEx modern RegEx with Unicode support
111111
// 'unicorn/prefer-code-point': 'error',
112112
// '@masknet/no-builtin-base64': 'warn', // Note: it fixes to Node's Buffer
113113
/// type safety

packages/backup-format/src/normalize/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function normalizeBackup(data: unknown): Promise<NormalizedBackup.D
1818

1919
// fix invalid URL
2020
normalized.settings.grantedHostPermissions = normalized.settings.grantedHostPermissions.filter((url) =>
21-
/^(http|<all_urls>)/.test(url),
21+
/^(http|<all_urls>)/u.test(url),
2222
)
2323
return normalized
2424
}

packages/encryption/src/network-encoding/twitter.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function TwitterDecoderText(raw: string): Option<string> {
5353
if (!raw) return None
5454
if (!raw.includes('%20') || !raw.includes('%40')) return None
5555
const payloadLink = parseURLs(raw)
56-
.map((x) => x.replace(/\u2026$/, ''))
56+
.map((x) => x.replace(/\u2026$/u, ''))
5757
.filter((x) => x.endsWith('%40'))[0]
5858
if (!URL.canParse(payloadLink)) return None
5959
const { search, pathname } = new URL(payloadLink)
@@ -63,10 +63,9 @@ function TwitterDecoderText(raw: string): Option<string> {
6363
'\u{1F3BC}' +
6464
payload
6565
// https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1476
66-
// eslint-disable-next-line unicorn/better-regex
67-
.replace(/^PostData_v\d=/i, '')
68-
.replace(/^%20/, '')
69-
.replace(/%40$/, '')
66+
.replace(/^PostData_v\d=/iu, '')
67+
.replace(/^%20/u, '')
68+
.replace(/%40$/u, '')
7069
.replace('-', '+')
7170
.replace('_', '=')
7271
.replaceAll('.', '|') +

packages/mask-sdk/main/wallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class EthereumEventEmitter extends EventTarget implements Ethereum.MaskEthereumE
3232
}
3333
class MaskProvider extends EthereumEventEmitter implements Ethereum.ProviderObject {
3434
async request(param: any): Promise<any> {
35-
const stack = new Error().stack?.replace(/^Error\n/, '')
35+
const stack = new Error().stack?.replace(/^Error\n/u, '')
3636
const result = await contentScript.eth_request(param)
3737
if (result.e) {
3838
result.e.stack = `MaskEthereumProviderRpcError: ${result.e.message}\n${stack}`

packages/mask/background/services/backup/internal_wallet_backup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function keyToJWK(key: string, type: 'public'): EC_Public_JsonWebKey
110110
function keyToJWK(key: string, type: 'private'): EC_Private_JsonWebKey
111111
function keyToJWK(key: string, type: 'public' | 'private'): JsonWebKey {
112112
const ec = new EC('secp256k1')
113-
const key_ = key.replace(/^0x/, '')
113+
const key_ = key.replace(/^0x/u, '')
114114
const keyPair = type === 'public' ? ec.keyFromPublic(key_) : ec.keyFromPrivate(key_)
115115
const pubKey = keyPair.getPublic()
116116
const privKey = keyPair.getPrivate()
@@ -130,7 +130,7 @@ function base64(numbers: number[]) {
130130
}
131131
function keyToAddr(key: string, type: 'public' | 'private'): string {
132132
const ec = new EC('secp256k1')
133-
const key_ = key.replace(/^0x/, '')
133+
const key_ = key.replace(/^0x/u, '')
134134
const keyPair = type === 'public' ? ec.keyFromPublic(key_) : ec.keyFromPrivate(key_)
135135
return wallet_ts.EthereumAddress.from(Buffer.from(keyPair.getPublic(false, 'array'))).address
136136
}

packages/mask/background/services/backup/internal_wallet_restore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function internal_wallet_restore(backup: NormalizedBackup.WalletBac
4242
for (const wallet of backup) {
4343
try {
4444
const wallets = await getWallets()
45-
const matchedDefaultNameFormat = wallet.name.match(/Wallet (\d+)/)
45+
const matchedDefaultNameFormat = wallet.name.match(/Wallet (\d+)/u)
4646
const digitIndex = matchedDefaultNameFormat?.[1]
4747
let name = wallet.name
4848
if (!name) {

packages/mask/background/services/helper/sandboxed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export async function fetchSandboxedPluginManifest(addr: string): Promise<unknow
77
return JSON.parse(
88
text
99
.split('\n')
10-
.filter((x) => !x.match(/^ +\/\//))
10+
.filter((x) => !x.match(/^ +\/\//u))
1111
.join('\n'),
1212
)
1313
}

packages/mask/background/services/helper/short-link-resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async function resolver(u: string): Promise<string | null> {
1212
credentials: 'omit',
1313
referrerPolicy: 'no-referrer',
1414
})
15-
const url = text.match(/URL=(.+).><\/noscript/)?.[1]
15+
const url = text.match(/URL=(.+).><\/noscript/u)?.[1]
1616
if (url) cache.set(u, url)
1717
return url ?? null
1818
}

packages/mask/background/services/wallet/services/legacyWallet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async function recoverWalletFromMnemonicWords(
7373

7474
async function recoverWalletFromPrivateKey(privateKey: string) {
7575
const ec = new EC('secp256k1')
76-
const privateKey_ = privateKey.replace(/^0x/, '').trim() // strip 0x
76+
const privateKey_ = privateKey.replace(/^0x/u, '').trim() // strip 0x
7777
const key = ec.keyFromPrivate(privateKey_)
7878
return {
7979
address: wallet_ts.EthereumAddress.from(key.getPublic(false, 'array') as any).address,
@@ -85,7 +85,7 @@ async function recoverWalletFromPrivateKey(privateKey: string) {
8585
}
8686

8787
function privateKeyVerify(key: string) {
88-
if (!/[\da-f]{64}/i.test(key)) return false
88+
if (!/[\da-f]{64}/iu.test(key)) return false
8989
const k = new BigNumber(key, 16)
9090
const n = new BigNumber('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141', 16)
9191
return !k.isZero() && k.isLessThan(n)

packages/mask/background/services/wallet/services/wallet/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ async function addWalletFromPrivateKey(
370370
coin: api.Coin.Ethereum,
371371
name,
372372
password: masterPassword,
373-
privateKey: privateKey.replace(/^0x/, '').trim(),
373+
privateKey: privateKey.replace(/^0x/u, '').trim(),
374374
})
375375
if (!imported?.StoredKey) throw new Error('Failed to import the wallet.')
376376
const created = await Mask.createAccountOfCoinAtPath({
@@ -449,7 +449,7 @@ export async function generateAddressFromPrivateKey(privateKey: string) {
449449
coin: api.Coin.Ethereum,
450450
name: '',
451451
password: masterPassword,
452-
privateKey: privateKey.replace(/^0x/, '').trim(),
452+
privateKey: privateKey.replace(/^0x/u, '').trim(),
453453
})
454454
if (!imported?.StoredKey) throw new Error('Failed to import the wallet.')
455455
const created = await Mask.createAccountOfCoinAtPath({

0 commit comments

Comments
 (0)