Browse Source

Fix: correct trie tokenizer behavior

SukkaW 1 year ago
parent
commit
175ba65127
1 changed files with 4 additions and 3 deletions
  1. 4 3
      Build/lib/trie.ts

+ 4 - 3
Build/lib/trie.ts

@@ -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) {
-      acc.push('.');
+    if (index > 0) {
+      acc.push('.', token);
+    } else if (token.length > 0) {
+      acc.push(token);
     }
     }
-    acc.push(token);
     return acc;
     return acc;
   }, []);
   }, []);
 };
 };