Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent Text Length Validation with Line Breaks in Textfield Options #4448

Open
rloes opened this issue Jan 4, 2025 · 0 comments
Open
Labels

Comments

@rloes
Copy link

rloes commented Jan 4, 2025

Preconditions (*)

  1. OpenMage version 20.1.1.
  2. Environment includes use of text field options for products with max character limits.

Steps to reproduce (*)

  1. Go to a product page with a textfield option that has a defined maximum character limit.
  2. Enter text into the textfield that includes line breaks ("\n") positioned within the text, not at the beginning or end. Ensure the total number of characters, counting each line break as a single character, exactly matches the character limit.
  3. Submit the form to add the product to the cart.

Expected result (*)

  1. The text should be validated correctly by JavaScript as the number of characters (counting line breaks as single characters) matches the limit, allowing the product to be added to the cart without any errors.

Actual result (*)

  1. JavaScript validation passes and the form submits, but Magento returns an error stating "text is too long". This occurs because line breaks are counted as two characters ("\r\n") in backend validation, exceeding the character limit.

Proposed Solution

  1. Adjust the counting mechanism in app/code/local/Mage/Catalog/Model/Product/Option/Type/Text.php to handle line breaks correctly by accounting for carriage returns ("\r") and adjusting the character count accordingly, ensuring the trim() function’s effect is considered in the character validation process.
  2. Consider whether there is a more suitable place or method to normalize text input before validation. Could normalization be applied earlier in the data handling process to prevent such errors and ensure data consistency across different system layers?
@rloes rloes added the bug label Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant