diff --git a/core/i18nTextCollector.php b/core/i18nTextCollector.php
index e83f380fc..7be917b81 100644
--- a/core/i18nTextCollector.php
+++ b/core/i18nTextCollector.php
@@ -298,7 +298,8 @@ class i18nTextCollector extends Object {
// 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 @@ class i18nTextCollector extends Object {
*/
public function langArrayCodeForEntitySpec($entityFullName, $entitySpec) {
$php = '';
+ $eol = PHP_EOL;
$entityParts = explode('.', $entityFullName);
if(count($entityParts) > 1) {
@@ -338,15 +340,15 @@ class i18nTextCollector extends Object {
$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 @@ class i18nTextCollector extends Object {
// 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 @@ class i18nTextCollector extends Object {
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);
diff --git a/parsers/SQLFormatter.php b/parsers/SQLFormatter.php
index bade1e92c..2b2766bd9 100644
--- a/parsers/SQLFormatter.php
+++ b/parsers/SQLFormatter.php
@@ -45,8 +45,9 @@ class SQLFormatter extends Object {
* 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) ? "
\n" : "\n";
+ $breakToken = ($useHtmlFormatting) ? "
$eol" : $eol;
$sql = preg_replace('/[^\n](' . $token . ')/', $breakToken . '$1', $sql);
}
diff --git a/tests/SQLFormatterTest.php b/tests/SQLFormatterTest.php
index 0c1028b3b..faa5b5b43 100644
--- a/tests/SQLFormatterTest.php
+++ b/tests/SQLFormatterTest.php
@@ -16,6 +16,7 @@ SELECT Test.Foo, Test.Bar
FROM Test
WHERE 'From' = "Where"
SQL;
+
$this->assertEquals($formatter->formatPlain($sqlBefore), $sqlAfter,
'correct replacement of newlines and don\'t replace non-uppercase tokens'
);
diff --git a/tests/i18n/i18nTextCollectorTest.php b/tests/i18n/i18nTextCollectorTest.php
index 08a7c7d97..46ccfa9e6 100644
--- a/tests/i18n/i18nTextCollectorTest.php
+++ b/tests/i18n/i18nTextCollectorTest.php
@@ -280,10 +280,12 @@ _t(
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 @@ PHP;
$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 @@ PHP;
$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 = <<