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

TypeError: Cannot call method 'replace' of null #27

Closed
gambhiro opened this issue May 15, 2013 · 4 comments · Fixed by #31
Closed

TypeError: Cannot call method 'replace' of null #27

gambhiro opened this issue May 15, 2013 · 4 comments · Fixed by #31

Comments

@gambhiro
Copy link
Contributor

I got TypeError: Cannot call method 'replace' of null for line 74 in lunr.js.

Just inserting a check for null argument fixes it:

lunr.tokenizer = function (str) {
  if (str == null) return new Array // check for null argument
  if (Array.isArray(str)) return str

  var str = str.replace(/^\s+/, '')
  ...
@olivernn
Copy link
Owner

Good catch and thanks for reporting this bug! I'd be happy to accept a pull request with a fix for this issue.

You don't need to change the 'built' version of the library, just the individual files, in this case just lib/tokenizer.js.

Also, include a simple test to prevent any regressions of this bug in the future, you should add your test to test/tokenizer_test.js.

Lastly, it might be a little more idiomatic JavaScript to change your modification to be like the following:

if (!str) return []

Let me know if you don't feel comfortable with contributing a patch and I'll put together a fix.

@gambhiro gambhiro mentioned this issue May 16, 2013
@gambhiro
Copy link
Contributor Author

Interesting excercise for a one-line fix :) Thanks for the mini-tutorial too.

@olivernn
Copy link
Owner

I've pushed a new version, 0.3.2, which includes a fix for this issue.

@gambhiro
Copy link
Contributor Author

Great, thanks!

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

Successfully merging a pull request may close this issue.

2 participants