Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BUGFIX Fixed newlines working properly across different platforms - W…

…indows, for example, won't work properly with just \n so use PHP_EOL for a cross-platform solution

MINOR Fixed appropriate failing tests to use PHP_EOL (from r92220)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@92460 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
commit abb04b2ea4aa4f5490cbc8979d8fd68b90e144b5 1 parent a099f79
Ingo Schommer chillu authored
15 core/i18nTextCollector.php
View
@@ -298,7 +298,8 @@ protected function entitySpecFromRegexMatches($regs, $_namespace = null) {
// remove starting comma and any newlines
- $prio = ($regs[10]) ? trim(preg_replace('/\n/','',substr($regs[10],1))) : null;
+ $eol = PHP_EOL;
+ $prio = ($regs[10]) ? trim(preg_replace("/$eol/", '', substr($regs[10],1))) : null;
// remove wrapping quotes
$comment = ($regs[12]) ? substr($regs[12],1,-1) : null;
@@ -320,6 +321,7 @@ protected function entitySpecFromRegexMatches($regs, $_namespace = null) {
*/
public function langArrayCodeForEntitySpec($entityFullName, $entitySpec) {
$php = '';
+ $eol = PHP_EOL;
$entityParts = explode('.', $entityFullName);
if(count($entityParts) > 1) {
@@ -338,15 +340,15 @@ public function langArrayCodeForEntitySpec($entityFullName, $entitySpec) {
$php .= '$lang[\'' . $this->defaultLocale . '\'][\'' . $namespace . '\'][\'' . $entity . '\'] = ';
if ($prio) {
- $php .= "array(\n\t'" . $value . "',\n\t" . $prio;
+ $php .= "array($eol\t'" . $value . "',$eol\t" . $prio;
if ($comment) {
- $php .= ",\n\t'" . $comment . '\'';
+ $php .= ",$eol\t'" . $comment . '\'';
}
- $php .= "\n);";
+ $php .= "$eol);";
} else {
$php .= '\'' . $value . '\';';
}
- $php .= "\n";
+ $php .= "$eol";
return $php;
}
@@ -358,6 +360,7 @@ protected function writeMasterStringFile($entitiesByModule) {
// Write each module language file
if($entitiesByModule) foreach($entitiesByModule as $module => $entities) {
$php = '';
+ $eol = PHP_EOL;
// Create folder for lang files
$langFolder = $this->baseSavePath . '/' . $module . '/lang';
@@ -380,7 +383,7 @@ protected function writeMasterStringFile($entitiesByModule) {
user_error('i18nTextCollector->writeMasterStringFile(): Invalid PHP language file. Error: ' . $e->toString(), E_USER_ERROR);
}
- fwrite($fh, "<"."?php\n\nglobal \$lang;\n\n" . $php . "\n?".">");
+ fwrite($fh, "<"."?php{$eol}{$eol}global \$lang;{$eol}{$eol}" . $php . "{$eol}?".">");
fclose($fh);
//Debug::message("Created file: $langFolder/" . $this->defaultLocale . ".php", false);
3  parsers/SQLFormatter.php
View
@@ -45,8 +45,9 @@ public function formatHTML($sql) {
* messing with possible content fragments in the query.
*/
protected function addNewlines($sql, $useHtmlFormatting = false) {
+ $eol = PHP_EOL;
foreach(self::$newline_before_tokens as $token) {
- $breakToken = ($useHtmlFormatting) ? "<br />\n" : "\n";
+ $breakToken = ($useHtmlFormatting) ? "<br />$eol" : $eol;
$sql = preg_replace('/[^\n](' . $token . ')/', $breakToken . '$1', $sql);
}
1  tests/SQLFormatterTest.php
View
@@ -16,6 +16,7 @@ function testNewlineHanding() {
FROM Test
WHERE 'From' = "Where"
SQL;
+
$this->assertEquals($formatter->formatPlain($sqlBefore), $sqlAfter,
'correct replacement of newlines and don\'t replace non-uppercase tokens'
);
12 tests/i18n/i18nTextCollectorTest.php
View
@@ -280,10 +280,12 @@ function testNewlinesInEntityValues() {
Line 2'
);
PHP;
+
+ $eol = PHP_EOL;
$this->assertEquals(
$c->collectFromCode($php, 'mymodule'),
array(
- 'Test.NEWLINESINGLEQUOTE' => array("Line 1\nLine 2",null,null)
+ 'Test.NEWLINESINGLEQUOTE' => array("Line 1{$eol}Line 2",null,null)
)
);
@@ -297,7 +299,7 @@ function testNewlinesInEntityValues() {
$this->assertEquals(
$c->collectFromCode($php, 'mymodule'),
array(
- 'Test.NEWLINEDOUBLEQUOTE' => array("Line 1\nLine 2",null,null)
+ 'Test.NEWLINEDOUBLEQUOTE' => array("Line 1{$eol}Line 2",null,null)
)
);
}
@@ -312,18 +314,18 @@ function testLangArrayCodeForEntity() {
$this->assertEquals(
$c->langArrayCodeForEntitySpec('Test.SIMPLE', array('Simple Value')),
- "\$lang['{$locale}']['Test']['SIMPLE'] = 'Simple Value';\n"
+ "\$lang['{$locale}']['Test']['SIMPLE'] = 'Simple Value';" . PHP_EOL
);
$this->assertEquals(
// single quotes should be properly escaped by the parser already
$c->langArrayCodeForEntitySpec('Test.ESCAPEDSINGLEQUOTES', array("Value with \'Escaped Single Quotes\'")),
- "\$lang['{$locale}']['Test']['ESCAPEDSINGLEQUOTES'] = 'Value with \'Escaped Single Quotes\'';\n"
+ "\$lang['{$locale}']['Test']['ESCAPEDSINGLEQUOTES'] = 'Value with \'Escaped Single Quotes\'';" . PHP_EOL
);
$this->assertEquals(
$c->langArrayCodeForEntitySpec('Test.DOUBLEQUOTES', array('Value with "Double Quotes"')),
- "\$lang['{$locale}']['Test']['DOUBLEQUOTES'] = 'Value with \"Double Quotes\"';\n"
+ "\$lang['{$locale}']['Test']['DOUBLEQUOTES'] = 'Value with \"Double Quotes\"';" . PHP_EOL
);
$php = <<<PHP
Please sign in to comment.
Something went wrong with that request. Please try again.