Skip to content

Commit 873113d

Browse files
authored
Merge pull request #102 from ulvesked/master
Escape Locale Strings before adding to array
2 parents b4091de + 015ba2a commit 873113d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/PKPass.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public function addLocaleStrings($language, $strings = [])
237237
}
238238
$dictionary = "";
239239
foreach($strings as $key => $value) {
240-
$dictionary .= '"'. $key .'" = "'. $value .'";'. PHP_EOL;
240+
$dictionary .= '"'. $this->escapeLocaleString($key) .'" = "'. $this->escapeLocaleString($value) .'";'. PHP_EOL;
241241
}
242242
$this->locales[$language] = $dictionary;
243243

@@ -665,4 +665,17 @@ protected function clean()
665665

666666
return true;
667667
}
668+
669+
protected static $escapeChars = [
670+
"\n" => "\\n",
671+
"\r" => "\\r",
672+
"\"" => "\\\"",
673+
"\\" => "\\\\"
674+
];
675+
/**
676+
* Escapes strings for use in locale files
677+
*/
678+
protected function escapeLocaleString($string) {
679+
return strtr($string, self::$escapeChars);
680+
}
668681
}

0 commit comments

Comments
 (0)