Problem observed by BR0kEN in #2863756-10: Unnecessary t() calls in tests. Tests are using both double-quoted and single-quoted strings for messages. Single quotes and double quotes are used interchangeably for strings throughout the code.
Coding standards do not require the use of either, but advise consistency. From https://www.drupal.org/docs/develop/standards/coding-standards#quotes :
Drupal does not have a hard standard for the use of single quotes vs. double quotes. Where possible, keep consistency within each module, and respect the personal style of other developers.
With that caveat in mind, single quote strings should be used by default. Their use is recommended except in two cases:
1. Deliberate in-line variable interpolation, e.g. "$header".
2. Translated strings where one can avoid escaping single quotes by enclosing the string in double quotes. One such string would be "He's a good person." It would be 'He\'s a good person.' with single quotes. Such escaping may not be handled properly by .pot file generators for text translation, and it's also somewhat awkward to read.
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | interdiff-2865115-16-17.txt | 468 bytes | l0ke |
| #17 | password_policy-7.x-2.x-quote_strings_consistently-2865115-17.patch | 6.8 KB | l0ke |
| #16 | interdiff-2865115-14-16.txt | 994 bytes | l0ke |
| #16 | password_policy-7.x-2.x-quote_strings_consistently-2865115-16.patch | 6.8 KB | l0ke |
| #15 | interdiff-2865115-8-15.txt | 2.11 KB | aohrvetpv |
Comments
Comment #2
aohrvetpv commentedComment #3
l0keWill work on it. Just to confirm:
The quoting in password_policy.test file be fixed in #2863756: Unnecessary t() calls in tests and here we need to check all other files, am I right?
Comment #4
l0keCompletely not properly used
t()function here, so replaced with inline variables.Didn't do any changes is password_policy.test
Comment #6
l0keOh, didn't notice it's for 1.x.
Comment #7
aohrvetpv commentedThanks very much for the patches! I think the schema descriptions containing single quotes should use double quotes per (2) from the Drupal Coding Standards section on quotes:
These strings are not translated directly using
t(), but my understanding is the Schema API does translate them.I was hoping to also change the .test strings in this issue so that we can fix all the strings in one commit (per branch).
Comment #8
l0kePatch for 2.x has everything.
As for 1.x
COMMENTproperty in database.So I did changes to JavaScript also.
Comment #9
aohrvetpv commentedThis change concerns me:
Substituting variables without sanitizing may allow for SQL injection.
t()is probably wrong, but I suspect this isn't the proper way to substitute for queries.Comment #10
aohrvetpv commentedUnrelated issue:
It looks like the symbol count constraint does not count backslashes due to a missing escape character.
Comment #11
aohrvetpv commentedI was wrong in #10. It looks like
preg_quote()takes care of the escaping.However I noticed ~ and ` are not counted as symbols. Shouldn't they be?
Comment #12
aohrvetpv commentedRe #9, I think the proper way to substitute is to use placeholders and the arguments parameter to
leftJoin(). See: https://api.drupal.org/api/drupal/includes!database!select.inc/function/...Comment #13
aohrvetpv commentedCreated issue for #11:
#2865506: Symbol count constraint does not count backtick and tilde
Comment #14
aohrvetpv commentedMade change suggested in #12.
Comment #15
aohrvetpv commentedChanged a few more strings to use single quotes.
Comment #16
l0ke#15 Patch for 7.x-1.x RTBC.
#14Placeholders++
But I don't like that use of variables
$condition$argumentswe define them to use only once inleftJoin(), I would suggest to use inline statement.Comment #17
l0keJust noticed
symbol_count_symbolsstring insymbol_count.incis corruptedshould be <code>'!@#$%^&*()_+=-|}{"?:><,./;\'\\[]'Difference is in this part:
wrong
\'\[]correct
\'\\[]I guess it affects #2865506: Symbol count constraint does not count backtick and tilde as well
Comment #20
aohrvetpv commentedCommitted #16. We can investigate #17 in #2865506: Symbol count constraint does not count backtick and tilde.