kantord / LibreLingo

🐢 🌎 📚 a community-owned language-learning platform
https://librelingo.app
GNU Affero General Public License v3.0
1.97k stars 215 forks source link

Extra Whitespace in Input Causes Incorrect Answer #3378

Open greenmachine112 opened 5 months ago

greenmachine112 commented 5 months ago

When accepting manually typed input from users for translations, the user's answer is marked incorrect if there is any extra whitespace at the end of the input. This error is exclusive to trailing whitespace, as extra whitespace between or before words does not cause this issue. For example, when translating the phrase "El come pizza" to English, the correct translation "He eats pizza" is marked incorrect if entered as "He eats pizza " (with an extra space at the end).

Steps to Reproduce: Navigate to the website and begin a lesson. Enter the correct translation for any text input with an extra space at the end (i.e., "He eats pizza "). Submit the answer.

Expected Result: The app should trim any trailing whitespace from input before validation, and mark the translation "He eats pizza " as correct.

Actual Result: The app notifies the user that a typo exists.

Impact: This issue can be frustrating for users as it penalizes them for a minor formatting error that does not affect the correctness of the translation.

Severity: Medium

Environment:

App Version: [insert app version here] Operating System: [insert operating system here] Device: [insert device model here] Additional Information: The issue appears to be related to how the app validates user input. It likely does a direct string comparison without trimming whitespace. rstrip(), or varibaleTrim() would work.

Attachments: exhibit1 Screenshot of the incorrect answer message with extra whitespace in the input.

Suggested Fix: Update the input validation logic to trim leading and trailing whitespace from user inputs before comparing them to the correct answer.

twocs commented 5 months ago

The white space logic is in https://github.com/kantord/LibreLingo/blob/main/apps/answer-corrector/src/index.ts:8

const ignoreWhitespace = (form: string): string =>
  form.replace(/^\s+|\s+$/g, "").replace(/\s+/g, " ")

In principle, this will take all spaces (and tabs) at the beginning and end of a block of text and remove the white spaces. I tested on the animals on librelingo.app and was able to get a correct answer despite trailing white space. I do see the screenshot above does appear to demonstrate trailing whitespace causing an issue.

I will attach screenshots, but ultimately I would say more detail is required to understand the bug.

image image