forked from FoundKeyGang/FoundKey
require punycode conversion beforehand for admins
This commit is contained in:
parent
a35c98bbd5
commit
b3e34795c0
2 changed files with 5 additions and 8 deletions
|
@ -187,7 +187,7 @@ clearCachedFiles: "Clear cache"
|
|||
clearCachedFilesConfirm: "Are you sure that you want to delete all cached remote files?"
|
||||
blockedInstances: "Blocked Instances"
|
||||
blockedInstancesDescription: "List the hostnames of the instances that you want to\
|
||||
\ block. Listed instances will no longer be able to communicate with this instance. You can use an asterisk (*) as a placeholder for zero or more character(s)."
|
||||
\ block. Listed instances will no longer be able to communicate with this instance. Non-ASCII domain names must be encoded in punycode. You can use an asterisk (*) as a placeholder for zero or more character(s)."
|
||||
muteAndBlock: "Mutes and Blocks"
|
||||
mutedUsers: "Muted users"
|
||||
blockedUsers: "Blocked users"
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { toASCII } from 'punycode/';
|
||||
import { db } from '@/db/postgre.js';
|
||||
import { fetchMeta } from '@/misc/fetch-meta.js';
|
||||
import { Instance } from '@/models/entities/instance.js';
|
||||
|
@ -10,19 +9,17 @@ const deadThreshold = 7 * DAY;
|
|||
|
||||
/**
|
||||
* Returns whether a given host matches a wildcard pattern.
|
||||
* @param host instance host
|
||||
* @param pattern wildcard pattern containing an instance host
|
||||
* @param host punycoded instance host
|
||||
* @param pattern wildcard pattern containing a punycoded instance host
|
||||
* @returns whether the post matches the pattern
|
||||
*/
|
||||
function matchHost(host: Instance['host'], pattern: string): boolean {
|
||||
// Escape all of the regex special characters. Pattern from:
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
|
||||
const escape = (str: string): string => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
const re = new RegExp('^' + pattern.split('*').map(toASCII).map(escape).join('.*') + '$');
|
||||
const re = new RegExp('^' + pattern.split('*').map(escape).join('.*') + '$');
|
||||
|
||||
// Encode the domain in punycode in case it uses non-ascii
|
||||
const punycoded = toASCII(host);
|
||||
return re.test(punycoded);
|
||||
return re.test(host);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue