Problem/Motivation
The comment subject field limit of 64 characters is too short.
Steps to reproduce
- Do a Standard Drupal 11 installation. Make sure the Comment module is enabled
- Create a node of type Article
- View its page and post a comment. Try to fill more than 64 characters in the subject
- See that the field is limited. No more than 64 characters can be inserted
Proposed resolution
Increase the comment subject column from VARCHAR(64) to VARCHAR(255)
Remaining tasks
- [✓] - Fix & MR
- [ ] - Tests
User interface changes
The maximum length for a comment subject now is 255 characters.
Introduced terminology
None
API changes
None
Data model changes
The maximum length for a comment subject now is 255 characters.
Release notes snippet
NA
Original report by @mkpaul
For multibyte languages (in this case malayalam), the length of the comment subject line is too short and truncates the subject line. A fix to increase the length of subject fiels is as follows:
The length of th esubject line is defined in the comment table:
subject varchar(64) NOT NULL default '',
You can use phpmyqdmin or the mysql commandline to change this to something higher. Maximum is 255.
You will maybe also need to increase the number of chars you can put into the forms. Look for form_textfield in comment.module.
This problem exists for 4.6.* versions also.
Thanks Gerhard Killesreiter for the above fix!
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | comment_subject_line_is_too_short-25345-26.patch | 1.56 KB | interdruper |
Issue fork drupal-25345
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
forngren commentedAin't this fixed in later versions? if so, please close
Comment #2
yngens commentedI am on 5.x-dev and I made the following changes:
1. In comment.module at around 1539 I have changed maxlength to 255:
2. In DB's comment table I have set varchar(255) for 'subject' field.
Unfortunately, these steps did not help - it still displays the same short comment subjects for Russian language. What I am missing here?
Comment #4
tr commentedComment subject is still varchar(64) in Drupal 6, 7, and 8. Moving this feature request to the most current development version (D8) where it belongs.
Comment #5
andypostComment #18
casey commentedComment #20
casey commentedComment #25
interdruper commentedPatch for 10.2.x provided.
Comment #26
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
Comment #27
interdruper commented#25 missed update the function baseFieldDefinitions(). Re-rolled as #26 with the update.
Comment #28
andypostComment #29
smustgrave commentedIssue summary should follow standard issue template.
Also will need test coverage.
Comment #31
vidorado commentedI've created the MR and applied the patch from #27.
I believe the original post motivation is no longer an issue. Nowadays, nearly all DBs treat the VARCHAR() length as characters, not bytes. Perhaps in the old days when this issue was posted, it was bytes.
There has been motivation in this issue about a year ago, but I think that it was for the limited length of the subject field and not the multibyte problem.
I'm not pretty sure about what to test. I've made a couple of tests that check the maximum comment subject length limitation in action... but this behavior is common for all fields, so I'm a bit uneasy testing this only for the subject field and not for all fields, generally.
So, What do you think we should really test here @smustgrave?
Comment #33
vidorado commentedTrying to get feedback
Comment #34
smustgrave commentedFirst glance should have test coverage for the update hook. Simple check schema, run updates, check schema again
Comment #35
tr commentedI believe @vidorado is correct here.
I haven't done the research so I can't say for certain, but I believe all current DBs supported by Drupal use (or can use) a utf8 character set. In which case VARCHAR(n) means n characters, not n bytes. And yes, that would hold true for all fields, not just comment title fields.
In the case of MySQL, this change (from bytes to characters) took place between MySQL 4 and 5. We are now up to MySQL 8.
Drupal installation instructions say that utf8 encoding should be used when configuring the database (https://www.drupal.org/docs/getting-started/installing-drupal/create-a-d...). I don't know if this enforced at the core level or whether it is just assumed - regardless, I expect if you set pure ascii encoding on your database then Drupal core would fail in many places.
It would probably be a good idea to verify that utf8 encoding in the database is enforced by core, and perhaps to clarify the Drupal documentation about defining DB schemas to point out that VARCHAR() refers to characters not bytes. Note, https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Database%... does make a distinction between 'varchar' and 'varchar_ascii' in a schema definition, but doesn't make it explicit that 'varchar' refers to characters not bytes. Not sure it matters in most cases anymore, but IMO it's better to be explicit to dispel any doubts given that there is a long history in Drupal (and PHP, and SQL, and all code) of poor support for non-ascii character sets.
Comment #36
vidorado commentedThanks for pointing it out @tr.
I've seen that, at least for MySQL, the
utf8mb4character set is the default for new tables, so every table will have that, although the database could have been configured with another default character set.For PostgreSQL there is no possibility of setting a different character set for each table, and all of them inherit the character set of their database, but UTF8 is the standard nowadays. The same for SQLite. I haven't searched more in-detail.
Comment #37
vidorado commentedAfter many attempts, I still haven't been able to solve it. 😞
I've modified the test to be a subclass of
UpdatePathTestBase, but I can't update the subject field's max length. It keeps telling me: "The Subject field needs to be updated."There's something I don't fully understand about schema and field definitions.
I've read this article and checked out this repository, but without success.
In several places, I've seen suggestions to export the data, uninstall the field, reinstall it, and then restore the data—but that approach seems strange to me. What would make sense to me is altering the database column and updating the field definition, and the existing data should remain unchanged, since it's not a dramatic change.
Maybe someone with more expertise could help out?
Comment #38
smustgrave commentedFrom a quick glance I would say trust the test. Very possible the update hook isn't working fully, as the test looks correct to me.