Skip to content

Invalid words (e.g. "ZZZZZ") are accepted as guesses #8

Description

Copilot

Summary

Guesses that are not real words (e.g. ZZZZZ) are accepted by the game as valid guesses, even though they should be rejected.

Root cause

In src/components/GuessForm/GuessForm.js, guess validation only checks that the input is 5 characters A-Z:

const validateLength = /([A-Z]){5}/g

if (!guess.match(validateLength)) {
  return window.alert("Guess must have exactly 5 A-Z characters")
}

There is no check anywhere in the codebase that the guess is an actual valid word. The WORDS list in src/data.js is only used to pick the secret answer (sample(WORDS) in Game.js) - it is never used to validate a submitted guess.

Reproduction

const validateLength = /([A-Z]){5}/g;
"ZZZZZ".match(validateLength); // truthy -> guess is accepted

Typing ZZZZZ (or any other 5 letter A-Z string) into the guess input and submitting it is accepted as a normal guess, consuming one of the player's attempts, even though ZZZZZ is not in the word list and isn't a real word.

Suggested fix

Validate the submitted guess against a word list (either reuse WORDS from src/data.js, or add a separate, larger dictionary of acceptable guesses) before accepting it, and show an alert like "Not in word list" if it doesn't match, similar to the real Wordle.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions