pkp / pkp-lib

The library used by PKP's applications OJS, OMP and OPS, open source software for scholarly publishing.
https://pkp.sfu.ca
GNU General Public License v3.0
307 stars 447 forks source link

Exception when inputting large texts into short fields #9988

Open jonasraoni opened 5 months ago

jonasraoni commented 5 months ago

Describe the bug When trying to enter more characters than I'm allowed to, I receive an error message. In general all text fields that have limits should receive a max length limiter to help the user understand what's happening.

Another alternative would be to setup the database to cutoff the rest, but as a user, I wouldn't like it.

PHP Fatal error:  Uncaught PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'mailing_address' at row 1 in /var/www/html/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Database/Connection.php:570
Stack trace:
    #0 /var/www/html/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Database/Connection.php(570): PDOStatement->execute()
#1 /var/www/html/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Database/Connection.php(753): Illuminate\Database\Connection->Illuminate\Database\{closure}('update `users` ...', Array)
#2 /var/www/html/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Database/Connection.php(720): Illuminate\Database\Connection->runQueryCallback('update `users` ...', Array, Object(Closure))
#3 /var/www/html/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Database/Connection.php(577): Illuminate\Database\Connection->run('update `users` ...', Array, Object(Closure))
#4 /var/www/html/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Database/Connection.php(510): Illuminate\Database\Connection->affectingStatement('update `users` ...', Array)
#5 /var/www/html/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(3357): Illuminate\Database\Connection->update('update `users` ...', Array)
#6 /var/www/html/lib/pkp/classes/core/EntityDAO.php(196): Illuminate\Database\Query\Builder->update(Array)
#7 /var/www/html/lib/pkp/classes/user/DAO.php(270): PKP\core\EntityDAO->_update(Object(PKP\user\User))
#8 /var/www/html/lib/pkp/classes/user/Repository.php(121): PKP\user\DAO->update(Object(PKP\user\User))
#9 /var/www/html/lib/pkp/classes/user/form/BaseProfileForm.php(64): PKP\user\Repository->edit(Object(PKP\user\User))
#10 /var/www/html/lib/pkp/classes/user/form/ContactForm.php(137): PKP\user\form\BaseProfileForm->execute(emailUpdated: false)
#11 /var/www/html/lib/pkp/controllers/tab/user/ProfileTabHandler.php(124): PKP\user\form\ContactForm->execute()
#12 [internal function]: PKP\controllers\tab\user\ProfileTabHandler->saveContact(Array, Object(APP\core\Request))
#13 /var/www/html/lib/pkp/classes/core/PKPRouter.php(334): call_user_func(Array, Array, Object(APP\core\Request))
#14 /var/www/html/lib/pkp/classes/core/PKPComponentRouter.php(291): PKP\core\PKPRouter->_authorizeInitializeAndCallRequest(Array, Object(APP\core\Request), Array)
#15 /var/www/html/lib/pkp/classes/core/Dispatcher.php(165): PKP\core\PKPComponentRouter->route(Object(APP\core\Request))
#16 /var/www/html/lib/pkp/classes/core/PKPApplication.php(388): PKP\core\Dispatcher->dispatch(Object(APP\core\Request))
#17 /var/www/html/index.php(21): PKP\core\PKPApplication->execute()
#18 {main}

To Reproduce

  1. Enter more data than you're allowed to (normally 255 for simple text fields)
  2. Attempt to save

What application are you using? OJS 3.4

asmecher commented 5 months ago

VARCHAR(255) in MySQL means 255 bytes 😑

Are you sure? Looking at MySQL documentation for 8.0...

For definitions of character string columns (CHAR, VARCHAR, and the TEXT types), MySQL interprets length specifications in character units.

Maybe this changed at some point?

jonasraoni commented 5 months ago

Yep, this behavior was modified a long time ago, I'll update the description 😁