Skip to content

Do not automatically truncate text fields #19820

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cedric-anne
Copy link
Member

Checklist before requesting a review

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.

Description

Follows #19786.

When a value is truncated by CommonDBTM::filterValues(), the triggerred warning will, most of the time, not be seen by the user. The truncated part of the value may be important, for instance for an e-mail, and it is probably preferable to get a clear error rather than an invisible warning.
Also, some values may be truncated even if the database field is not limited to 255 chars.

I propose to remove this truncation, in order to trigger a SQL error when the value does not fit into the database field. The input value length should be either limited in the form, or checked by the prepareInputFor* methods.

glpi.CRITICAL:   *** Uncaught PHP Exception RuntimeException: "MySQL query error: Data too long for column 'email' at row 1 (1406) in SQL query "INSERT INTO `glpi_useremails` (`email`, `users_id`, `is_default`) VALUES ('this-is-a-very-long-email-address-that-should-trigger-a-sql-error-if-it-is-not-truncated-on-the-php-side-but-it-should-not-be-worse-that-the-current-truncation-logic-that-triggers-a-warning-that will-not-be-visible-for-most-of-the-users-that-will-think--that-everything-is-ok@example.com', '5', '1')"." at DBmysql.php line 369
  Backtrace :
  ./src/DBmysql.php:369                              
  ./src/DBmysql.php:1311                             DBmysql->doQuery()
  ./src/CommonDBTM.php:772                           DBmysql->insert()
  ./src/CommonDBTM.php:1388                          CommonDBTM->addToDB()
  ./src/User.php:1779                                CommonDBTM->add()
  ./src/User.php:1337                                User->updateUserEmails()
  ./src/CommonDBTM.php:1822                          User->post_updateItem()
  ./front/user.form.php:142                          CommonDBTM->update()
  ...Glpi/Controller/LegacyFileLoadController.php:59 require()
  ./vendor/symfony/http-kernel/HttpKernel.php:181    Glpi\Controller\LegacyFileLoadController->__invoke()
  ./vendor/symfony/http-kernel/HttpKernel.php:76     Symfony\Component\HttpKernel\HttpKernel->handleRaw()
  ./vendor/symfony/http-kernel/Kernel.php:197        Symfony\Component\HttpKernel\HttpKernel->handle()
  ./public/index.php:56                              Symfony\Component\HttpKernel\Kernel->handle()

@cedric-anne cedric-anne added this to the 11.0.0 milestone May 27, 2025
@cedric-anne cedric-anne force-pushed the 11.0/remove-text-autotruncate branch from 7e3951d to 99c93cd Compare May 27, 2025 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants