Use post-filtering for whitelist, like learnedWords

This commit is contained in:
Shane Kilkelly 2017-06-23 10:00:47 +01:00
parent 407283ee3c
commit a03bfbc020
2 changed files with 6 additions and 11 deletions

View file

@ -4,7 +4,7 @@ async = require 'async'
module.exports = SpellingAPIManager =
wordWhitelist: [
whitelist: [
'ShareLaTeX',
'sharelatex',
'LaTeX',
@ -23,12 +23,7 @@ module.exports = SpellingAPIManager =
ASpell.checkWords lang, words, (error, misspellings) ->
callback error, misspellings: misspellings
wordsToCheck = (request.words || []).map (word) ->
# blank out whitelisted words
if SpellingAPIManager.wordWhitelist.indexOf(word) == -1
word
else
'...'
wordsToCheck = request.words || []
if token?
LearnedWordsManager.getLearnedWords token, (error, learnedWords) ->
@ -38,7 +33,7 @@ module.exports = SpellingAPIManager =
return callback error if error?
result.misspellings = result.misspellings.filter (m) ->
word = words[m.index]
learnedWords.indexOf(word) == -1
learnedWords.indexOf(word) == -1 and SpellingAPIManager.whitelist.indexOf(word) == -1
callback error, result
else
check(wordsToCheck, callback)

View file

@ -84,12 +84,12 @@ describe "SpellingAPIManager", ->
describe 'with words from the whitelist', ->
beforeEach (done) ->
@whitelistWord = @SpellingAPIManager.wordWhitelist[0]
@words = ["One", @whitelistWord, "Two"]
@whitelistWord = @SpellingAPIManager.whitelist[0]
@words = ["One", "Two", @whitelistWord]
@SpellingAPIManager.runRequest @token, words: @words, (error, @result) => done()
it 'should ignore the white-listed word', ->
expect(@ASpell.checkWords.lastCall.args[1]).to.deep.equal ["One", "...", "Two"]
expect(@result.misspellings.length).to.equal @misspellings.length-1
describe "learnWord", ->
describe "without a token", ->