Fix: correct trie tokenizer behavior

This commit is contained in:
SukkaW 2024-06-30 00:30:46 +08:00
parent f10495fe67
commit 175ba65127

View File

@ -31,10 +31,11 @@ const createNode = (parent: TrieNode | null = null): TrieNode => {
const hostnameToTokens = (hostname: string): string[] => { const hostnameToTokens = (hostname: string): string[] => {
return hostname.split('.').reduce<string[]>((acc, token, index) => { return hostname.split('.').reduce<string[]>((acc, token, index) => {
if (index !== 0) { if (index > 0) {
acc.push('.'); acc.push('.', token);
} } else if (token.length > 0) {
acc.push(token); acc.push(token);
}
return acc; return acc;
}, []); }, []);
}; };