Skip to content

Commit

Permalink
Add error message for XLIFF file load (#1627)
Browse files Browse the repository at this point in the history
Throwing an exception when Symfony runs into issues when loading XLIFF
files. This will help with catching broken XML files due to translation
errors. Without any error handling, this would lead Symfony to use an
empty array as the array of translations when it is unable to read XML
files, and would make it delete all existing translations for such a
file.
  • Loading branch information
anvit committed Sep 15, 2023
1 parent e18c169 commit 7b7ffdb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions vendor/symfony/lib/i18n/sfMessageSource_XLIFF.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ public function &loadData($filename)
if (!$xml = simplexml_load_file($filename))
{
$error = false;
$xmlErrors = libxml_get_errors();
$errorMessage = '';
foreach ($xmlErrors as $error) {
$errorMessage .= sprintf("%s[File]: %s at line %s, column %s\n",
$error->message, $error->file, $error->line, $error->column);
}
if ($errorMessage) {
throw new sfException(sprintf("Could not load XML file:\n\n%s",
$errorMessage));
}

return $error;
}
Expand Down

0 comments on commit 7b7ffdb

Please sign in to comment.