Просмотр исходного кода

Use post-filtering for whitelist, like learnedWords

Shane Kilkelly 9 лет назад
Родитель
Сommit
a03bfbc020

+ 3 - 8
services/spelling/app/coffee/SpellingAPIManager.coffee

@@ -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)

+ 3 - 3
services/spelling/test/unit/coffee/SpellingAPIManagerTests.coffee

@@ -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", ->