From 5889adea901ab017748ea6a0bfdb7437e0db0a7a Mon Sep 17 00:00:00 2001 From: Matt DeBergalis Date: Wed, 25 Sep 2013 12:13:03 -0700 Subject: [PATCH] Various wordplay fixes: * Don't add blank lines to the dictionary. * Fix broken word length check in `score_word`. * Prevent event handler from submitting blank words. --- examples/wordplay/client/wordplay.js | 5 ++--- examples/wordplay/model.js | 7 ++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/wordplay/client/wordplay.js b/examples/wordplay/client/wordplay.js index f49212923b..acff55aaeb 100644 --- a/examples/wordplay/client/wordplay.js +++ b/examples/wordplay/client/wordplay.js @@ -132,9 +132,8 @@ Template.scratchpad.events({ 'click button, keyup input': function (evt) { var textbox = $('#scratchpad input'); // if we clicked the button or hit enter - if (evt.type === "click" || - (evt.type === "keyup" && evt.which === 13)) { - + if ((evt.type === "click" || (evt.type === "keyup" && evt.which === 13)) + && textbox.val()) { var word_id = Words.insert({player_id: Session.get('player_id'), game_id: game() && game()._id, word: textbox.val().toUpperCase(), diff --git a/examples/wordplay/model.js b/examples/wordplay/model.js index 5c609e4376..416c4db122 100644 --- a/examples/wordplay/model.js +++ b/examples/wordplay/model.js @@ -106,7 +106,8 @@ Meteor.methods({ // that the word is at least three chars, isn't already used, and is // possible to make on the board. if (game.clock === 0 - || word.length < 3 + || !word.word + || word.word.length < 3 || Words.find({game_id: word.game_id, word: word.word}).count() > 1 || paths_for_word(game.board, word.word).length === 0) { Words.update(word._id, {$set: {score: 0, state: 'bad'}}); @@ -129,8 +130,8 @@ Meteor.methods({ if (Meteor.isServer) { DICTIONARY = {}; _.each(Assets.getText("enable2k.txt").split("\n"), function (line) { - // Skip comment lines - if (line.indexOf("//") !== 0) { + // Skip blanks and comment lines + if (line && line.indexOf("//") !== 0) { DICTIONARY[line] = true; } });