Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
In \Drupal\Core\Database\Connection::query
the $trim_chars
contains two ordinary spaces but should contain one ordinary space and one non-breaking space.
// function or stored procedure in SQL. Trim any trailing delimiter to
// minimize false positives unless delimiter is allowed.
$trim_chars = " \t\n\r\0\x0B";
if (empty($options['allow_delimiter_in_query'])) {
$trim_chars .= ';';
}
$query = rtrim($query, $trim_chars);
Proposed resolution
Replace space (U+0020) with No-Break Space (U+00A0) to minimize false positives.
Comment | File | Size | Author |
---|---|---|---|
#10 | interdiff-7-10.txt | 1.56 KB | Krzysztof Domański |
#10 | 3143618-10.patch | 1.49 KB | Krzysztof Domański |
Comments
Comment #2
Krzysztof DomańskiComment #3
Krzysztof DomańskiComment #5
longwaveInstead of using the Unicode character directly should we use the \x escape to embed it in the string, so it's obvious to casual readers that it's not just a normal space?
Comment #6
BeakerboyGood catch! I knew there were two spaces there, but just assumed they were different. Should this string also include zero width space (U+200B)?
Comment #7
Krzysztof DomańskiAddressing #5.
Comment #9
daffie CreditAttribution: daffie commentedI do not think this change is good, because we are now hard coding the non-breaking space. We are also not mentioning all the other special characters.
@Krzysztof Domański: Thank you for the bug report, the fix and the added testing.
Comment #10
Krzysztof DomańskiThis can be a simple fix. https://www.php.net/manual/en/language.types.string.php
Comment #12
Krzysztof DomańskiUnrelated test failure. #3143812: Random test failure Table 'sequences' already exists.
Comment #13
daffie CreditAttribution: daffie commentedThe patch look good.
There is testing added for the bug fix.
It is for me RTBC.
I leave it for the committer to decide if there also needs to be testing for the UTF-8 version of the non-breaking space character. Which is "\xC2\xA0". See: https://en.wikipedia.org/wiki/Non-breaking_space.
Comment #14
alexpottCommitted aa97890 and pushed to 9.1.x. Thanks!