Skip to content

Commit

Permalink
Merge pull request #102 from ulvesked/master
Browse files Browse the repository at this point in the history
Escape Locale Strings before adding to array
  • Loading branch information
tschoffelen authored Jul 22, 2020
2 parents b4091de + 015ba2a commit 873113d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/PKPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function addLocaleStrings($language, $strings = [])
}
$dictionary = "";
foreach($strings as $key => $value) {
$dictionary .= '"'. $key .'" = "'. $value .'";'. PHP_EOL;
$dictionary .= '"'. $this->escapeLocaleString($key) .'" = "'. $this->escapeLocaleString($value) .'";'. PHP_EOL;
}
$this->locales[$language] = $dictionary;

Expand Down Expand Up @@ -665,4 +665,17 @@ protected function clean()

return true;
}

protected static $escapeChars = [
"\n" => "\\n",
"\r" => "\\r",
"\"" => "\\\"",
"\\" => "\\\\"
];
/**
* Escapes strings for use in locale files
*/
protected function escapeLocaleString($string) {
return strtr($string, self::$escapeChars);
}
}

0 comments on commit 873113d

Please sign in to comment.