Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues when word contains $ #8

Open
KamasamaK opened this issue Jan 18, 2019 · 3 comments
Open

Issues when word contains $ #8

KamasamaK opened this issue Jan 18, 2019 · 3 comments
Labels

Comments

@KamasamaK
Copy link

If I have something like

var triePrefixTree = require("trie-prefix-tree");

var allFunctionNames = triePrefixTree([]);

allFunctionNames.addWord("test$clone");

console.log(allFunctionNames.getPrefix("te"));

I get ["test", "test$clone"] even though I never added test.

Worse, if I do add test as below

var triePrefixTree = require("trie-prefix-tree");

var allFunctionNames = triePrefixTree([]);

allFunctionNames.addWord("test");
allFunctionNames.addWord("test$clone");

console.log(allFunctionNames.getPrefix("te"));

it produces an error: TypeError: Cannot create property 'c' on number '1'

@lyndseybrowning
Copy link
Owner

This issue has now been resolved in 1.5.1. If you have any questions, please get in touch.

@KamasamaK
Copy link
Author

@lyndseybrowning Thanks! It looks like the my second example does not produce an error anymore and gets the expected result. However, the first example still erroneously shows that test was added to the trie.

I've found that using $ is problematic in a few other situations too:

var triePrefixTree = require("trie-prefix-tree");

var allFunctionNames = triePrefixTree([]);

allFunctionNames.addWord("$test");
allFunctionNames.addWord("$");

console.log(allFunctionNames.getPrefix("te"));

Produces an error TypeError: Cannot create property '$' on number '1'.

var triePrefixTree = require("trie-prefix-tree");

var allFunctionNames = triePrefixTree([]);


allFunctionNames.addWord("$test");
allFunctionNames.addWord("$clone");

console.log(allFunctionNames.getPrefix("$te"));

Returns an empty array.

Should I not use this package if my words contain $ or are these things that can be addressed?

@lyndseybrowning
Copy link
Owner

The issue is that the Trie uses the $ key to indicate the end of a word. I'd rather not change that.

I think my previous fix can be used to resolve the remaining issues. I'll take a look and get back to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants