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

fix using autocomplete instead of autocomplete-plus to retrieve config #961

Merged
merged 1 commit into from Apr 9, 2018

Conversation

Projects
None yet
3 participants
@ariasuni
Contributor

ariasuni commented Mar 26, 2018

Fix #956.

How the actual code works

let result = atom.config.get('autocomplete.extraWordCharacters', {scope: scopeDescriptor})

is assigned to undefined, because the configuration key is invalid.

Then, POSSIBLE_WORD_CHARACTERS that aren’t in editor.nonWordCharacters are added at the end of result. In JavaScript, concatenating undefined and a letter, let’s say '_', produces a string: "undefined_".

The string is then incorporated in the regex there:

regex = new RegExp(`[${UnicodeLetters}${additionalWordChars.replace(']', '\\]')}]`)

As the regex already matches for ASCII letters, this doesn’t cause an issue in the general case.

The bug

When you add _ to editor.nonWordCharacters, then POSSIBLE_WORD_CHARACTERS and editor.nonWordCharacters are equals, then no concatenation takes place, and result stays undefined. Then, the above code line crash because you can’t use .replace() on undefined.

The fix

Using 'autocomplete-plus.extraWordCharacters' to effectively get the configuration and fix, in fact, two bugs:

  • If extraWordCharacters is not used, result is assigned to its default value (the empty string) instead of undefined, and the package will never crash.
  • If extraWordCharacters is used, now it’s taken into account!

Thanks to @BojanOro for his comment that set me on the right track.

@jasonrudolph jasonrudolph merged commit 8b5cdf9 into atom:master Apr 9, 2018

3 checks passed

DeepScan 0 new and 0 fixed issues
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@jasonrudolph

This comment has been minimized.

Member

jasonrudolph commented Apr 9, 2018

Thanks for this fix, @ariasuni. 🙇🍰

@droptablestar

This comment has been minimized.

droptablestar commented Apr 16, 2018

If I understand this fix correctly I should match 'autocomplete-plus.extraWordCharacters' with 'editor.nonWordCharacters'. I've done this but still seem to be having this issue.
'autocomplete-plus.extraWordCharacters' = /\()"':,.;<>~!@#$%^&*|+=[]{}`?-…_ and
'editor.nonWordCharacters' = /\()"':,.;<>~!@#$%^&*|+=[]{}`?-…_.

@ariasuni

This comment has been minimized.

Contributor

ariasuni commented Apr 16, 2018

autocomplete-plus is a core package, so you should wait for a new release of Atom including the new version containing the fix.

You don’t have to match the two settings; it’s precisely when they contain exactly the same characters that the bug is triggered.

@droptablestar

This comment has been minimized.

droptablestar commented Apr 16, 2018

@ariasuni Interesting...I am experiencing this issue even when both settings do not match. Looks like I'll wait :).

@ariasuni

This comment has been minimized.

Contributor

ariasuni commented Apr 16, 2018

@droptablestar the bug is also triggered if POSSIBLE_WORD_CHARACTERS become a superset of editor.nonWordCharacters. Is that your case?

@droptablestar

This comment has been minimized.

droptablestar commented Apr 16, 2018

@ariasuni Where would I find POSSIBLE_WORD_CHARACTERS?

@ariasuni

This comment has been minimized.

Contributor

ariasuni commented Apr 17, 2018

See

let result = atom.config.get('autocomplete.extraWordCharacters', {scope: scopeDescriptor})

The variable result is autocomplete-plus.extraWordCharacters, then characters that are in POSSIBLE_WORD_CHARACTERS but not in editor.nonWordCharacters are concatened to it.

Currently, POSSIBLE_WORD_CHARACTERS is editor.nonWordCharacters without _.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment