Problem/Motivation
I got the following error as I try to save a node when non-English language (Chinese in my case) is enabled. The problem does not exist when English is the default language.
PDOException: 在 dblog_watchdog() (行 157 在 D:\xampp\htdocs\modules\dblog\dblog.module).
When I catch the exception, I found the following issue:
Incorrect string value: '\xE6\x9F' for column 'link' at row 1
The problematic code is:
Database::getConnection('default', 'default')->insert('watchdog')
->fields(array('uid' => $user_uid,'type' => substr($log_entry['type'], 0, 64),'message' => $log_entry['message'],'variables' => serialize($log_entry['variables']),'severity' => $log_entry['severity'],'link' => substr($log_entry['link'], 0, 255), // <----- problematic'location' => $log_entry['request_uri'],'referer' => $log_entry['referer'],'hostname' => substr($log_entry['ip'], 0, 128),'timestamp' => $log_entry['timestamp'],
))
->execute();
In my case, the link is: 查看
So, substr($log_entry['link'], 0, 255) truncates in the middle of the Chinese characters: 查看.
I tried to reduce the substr length to 200: substr($log_entry['link'], 0, 200), then I don't see the problem.
I don't care about such logs, I'd be happy if it is just caught. But I'm sure there is a nice way to fix it.
To reproduce the issue one can for example store a node with a long URL alias including non-standard characters. You can use some of the Chinese characters above or just this exact URL alias:
åååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååååå
Proposed resolution
See patch.
Remaining tasks
User interface changes
API changes
Beta phase evaluation
Issue category | Bug because PDOExceptions |
---|---|
Prioritized changes | The main goal of this issue is to fix a bug and reduce fragility of code. The bug also exists in Drupal 7. |