Problem
In a YAML file, how should we escape a single quote character?
For example, in the default system.date.yml we use double quotes:
html_datetime:
name: 'HTML Datetime'
pattern:
php: 'Y-m-d\TH:i:sO'
intl: "yyyy-MM-dd'Tkk:mm:ssZZ"
However when this is written to the active store during installation is changes use single quotes:
html_datetime:
name: 'HTML Datetime'
pattern:
php: 'Y-m-d\TH:i:sO'
intl: 'yyyy-MM-dd''Tkk:mm:ssZZ'
Proposed solution
Use the single quote to escape a single quote so that config is not changed at all during installation.
Comment | File | Size | Author |
---|---|---|---|
#22 | 1944636.php-intl.22.patch | 7.82 KB | YesCT |
#22 | interdiff-21-22.txt | 959 bytes | YesCT |
#21 | 20-21-interdiff.txt | 571 bytes | alexpott |
#21 | 1944636.php-intl.21.patch | 7.83 KB | alexpott |
#20 | 17-20-interdiff.txt | 1.35 KB | alexpott |
Comments
Comment #1
alexpottHmmm very weird... initial investigations have not lead to a cause...
Using the following script with
drush scr
And
a.yml
contents being:Does not elicit this error... hmm... :(
Output:
Comment #2
vijaycs85Sorry for the wrong input @alexpott. here is the right one.
modules/system.date.yml
active/system.date.yml
Comment #3
vijaycs85Sorry for the wrong input @alexpott. here is the right one.
modules/system.date.yml
active/system.date.yml
Comment #3.0
alexpottUpdate issue to summary to reflect nature of issue
Comment #4
alexpottUpdating title to reflect nature of the issue.
Comment #5
alexpottThe only yaml file I could find with this issue so far is system.date.yml
Comment #6
vijaycs85Thanks for the patch @alexpott. I just tried it to test and found that this escaping stuff breaking the original functionality of the date format :( Here is the test:
formats.html_datetime.pattern.intl: 'yyyy-MM-dd''Tkk:mm:ssZZ'
When try to format a timestamp with this format(the same way, date_format() does):
We get below output:
Believe that the second string is the right format that we are expecting from configuration. Because of escaping of date and Yml are same and it is getting converted into something else?
Comment #7
vijaycs85Comment #8
alexpottHmmm.. actually what we are looking at here is are bugs! The intl format is supposed to be equivalent to the php format... so...
looks wrong... looking at http://userguide.icu-project.org/formatparse/datetime I think it should be...
And
should be
In order to test this you need to install intl extension from PECL
Comment #9
alexpottHmmm... this is actually part of a much larger critical bug. The DateTimePlus class's use of PECL intl extension is completely broken and un-tested.
If a server had the extension installed and the system.date:country.default configuration set dates would be broken due to passing the format string into IntlDateFormatter::format() and not the date object!!!
After getting the pecl extension installed I realised that none of tests can possible satisfy the conditions checked in DateTimePlus::canUseIntl()
Patch attached fixes this but I think more work needs to be done to test that our usage of the PECL intl extension meets Drupal's expectations. For now I've added a test that (if the extension is installed) confirms that the default formats supplied by system.date.yml match regardless of whether intl or php format strings are used.
Comment #10
alexpottFixing title
Comment #12
Gábor HojtsyTagging for D8MI. Thanks for digging this up :)
Comment #13
vijaycs85Seems we need to enable PECL intl extension to test @alexpott's new test cases. Do we need to raise issue wit environment team?
UPDATE: Blocked by #1947688: PECL intl extension needs to be installed and enabled
Comment #14
rfay#9: 1944636.php-intl.9.patch queued for re-testing.
Comment #15
rfayOk, unblocked. Thanks for all your work on this important task and for your patience.
Comment #16
alexpottFixed up some stuff in the new test and removed a hunk of unrelated changes that somehow crept into the patch.imo this is rtbc
Comment #17
YesCT CreditAttribution: YesCT commentednit, TRUE
http://drupal.org/node/1354
are we making the change from double quote to single because that's a standard ... or because that's what the config writer writes out? #1948284: [policy no patch] config save format and default yml file format and coding standards
These double single quotes look strange.
class needs a doc block
http://drupal.org/coding-standards/docs#classes
getInfo does not get a docblock.
http://drupal.org/node/325974
"There is no PHPDoc on this function since it is an inherited method."
I made it consistantly PECL Intl. I tried to google to see if it was intl or Intl outside of Drupal, but I'm not sure.
it seemed odd to me to see modules inbetween getInfo and setUp... I checked in Views and Entity Translation tests to see what might be usual, and it looks like the order is usually: $modules, getInfo(), setUp()
I'll put this back though if I shouldn't have made this reorder.
why is there a comment saying the default country is going to be set... but no code setting the default country?
nit, classes get an empty line before the last curly brace.
http://drupal.org/node/1353118
... might not actually be standard. hard to find a reference to it.
Comment #18
arlinsandbulte CreditAttribution: arlinsandbulte commentedShould this even be called the 'PECL' Intl extension?
According to http://drupal.org/node/1947688#comment-7232058 it is included with php now.
Perhaps it could better be described as the 'php5-intl package'
Comment #19
YesCT CreditAttribution: YesCT commentedanswering my own question, I applied the patch, installed the site and checked sites/default/files/config_sr16xvf6UHg6JTX1XgkgHqv9Uremgx6s6x6g4MQzXFw/active/system.date.yml
and the single quoting matches what is in this patch for those changed lines.
Comment #20
alexpott@arlinsandbulte you're right... it should be PHP's Intl extension... copying what they do here http://www.php.net/manual/en/intro.intl.php
Re-rolled to remove some commented out code and incorrect references to PECL.
Comment #21
alexpottugh...
Comment #22
YesCT CreditAttribution: YesCT commentedthis should be public:
http://drupal.org/node/325974
and this can wrap to 80 chars.
---
I looked at this change:
- 'PECL Intl extension needs to be installed and enabled.',
+ 'PHP\'s Intl extension needs to be installed and enabled.',
and http://drupal.org/coding-standards#quotes
says:
since it's not a translated string that keeping it in single quotes is ok.
So this looks ok to me.
Comment #24
alexpott#22: 1944636.php-intl.22.patch queued for re-testing.
Comment #25
alexpott#22: 1944636.php-intl.22.patch queued for re-testing.
Comment #26
YesCT CreditAttribution: YesCT commented#22: 1944636.php-intl.22.patch queued for re-testing.
Comment #27
arlinsandbulte CreditAttribution: arlinsandbulte commentedLet's get this critical off the list!
Comment #28
catchLooks good to me. Committed/pushed to 8x, thanks!
Comment #29
xmacinfoCan we get a follow up to display on the Status Report page (admin/reports/status) if the PECL Intl extension is installed?
Comment #31
jaredsmith CreditAttribution: jaredsmith commentedThis seems to have popped up again, as reported in http://drupal.org/node/2000384
Comment #31.0
jaredsmith CreditAttribution: jaredsmith commentedFix some formatting issues and shorten for clarity.