mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX: More fixes to i18n text collection with escaping of quotes
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@81420 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
8ee9373807
commit
5a9ca7d682
@ -181,6 +181,7 @@ class i18nTextCollector extends Object {
|
|||||||
'([[:space:]]*,[[:space:]]*[^,)]*)?([[:space:]]*,' . // priority (optional)
|
'([[:space:]]*,[[:space:]]*[^,)]*)?([[:space:]]*,' . // priority (optional)
|
||||||
'[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))?[[:space:]]*' . // comment (optional)
|
'[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))?[[:space:]]*' . // comment (optional)
|
||||||
'\)';
|
'\)';
|
||||||
|
|
||||||
while (ereg($regexRule, $content, $regs)) {
|
while (ereg($regexRule, $content, $regs)) {
|
||||||
$entitiesArr = array_merge($entitiesArr, (array)$this->entitySpecFromRegexMatches($regs));
|
$entitiesArr = array_merge($entitiesArr, (array)$this->entitySpecFromRegexMatches($regs));
|
||||||
|
|
||||||
@ -282,13 +283,19 @@ class i18nTextCollector extends Object {
|
|||||||
|
|
||||||
// remove wrapping quotes
|
// remove wrapping quotes
|
||||||
$value = ($regs[2]) ? substr($regs[2],1,-1) : null;
|
$value = ($regs[2]) ? substr($regs[2],1,-1) : null;
|
||||||
|
|
||||||
$value = ereg_replace("([^\\])['\"][[:space:]]*.[[:space:]]*['\"]",'\\1',$value);
|
$value = ereg_replace("([^\\])['\"][[:space:]]*\.[[:space:]]*['\"]",'\\1',$value);
|
||||||
|
|
||||||
// only escape quotes when wrapped in double quotes, to make them safe for insertion
|
// only escape quotes when wrapped in double quotes, to make them safe for insertion
|
||||||
// into single-quoted PHP code. If they're wrapped in single quotes, the string should
|
// into single-quoted PHP code. If they're wrapped in single quotes, the string should
|
||||||
// be properly escaped already
|
// be properly escaped already
|
||||||
if(substr($regs[2],0,1) == '"') $value = addcslashes($value,'\'');
|
if(substr($regs[2],0,1) == '"') {
|
||||||
|
// Double quotes don't need escaping
|
||||||
|
$value = str_replace('\\"','"', $value);
|
||||||
|
// But single quotes do
|
||||||
|
$value = str_replace("'","\\'", $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// remove starting comma and any newlines
|
// remove starting comma and any newlines
|
||||||
$prio = ($regs[10]) ? trim(preg_replace('/\n/','',substr($regs[10],1))) : null;
|
$prio = ($regs[10]) ? trim(preg_replace('/\n/','',substr($regs[10],1))) : null;
|
||||||
|
@ -70,17 +70,23 @@ class i18nTextCollectorTest extends SapphireTest {
|
|||||||
$php = <<<PHP
|
$php = <<<PHP
|
||||||
_t(
|
_t(
|
||||||
'Test.CONCATENATED',
|
'Test.CONCATENATED',
|
||||||
'Line 1' .
|
'Line 1 and ' .
|
||||||
'Line 2' .
|
'Line \'2\' and ' .
|
||||||
'Line 3',
|
'Line "3"',
|
||||||
PR_MEDIUM,
|
PR_MEDIUM,
|
||||||
'Comment'
|
'Comment'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
_t(
|
||||||
|
'Test.CONCATENATED2',
|
||||||
|
"Line \"4\" and " .
|
||||||
|
"Line 5");
|
||||||
PHP;
|
PHP;
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$c->collectFromCode($php, 'mymodule'),
|
$c->collectFromCode($php, 'mymodule'),
|
||||||
array(
|
array(
|
||||||
'Test.CONCATENATED' => array("Line 1Line 2Line 3",'PR_MEDIUM','Comment')
|
'Test.CONCATENATED' => array("Line 1 and Line \\'2\\' and Line \"3\"",'PR_MEDIUM','Comment'),
|
||||||
|
'Test.CONCATENATED2' => array("Line \"4\" and Line 5",null,null)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user