mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Fix language-loading infinite loop when throwing exceptions
This loop has existed since the very beginning, and was only ever papered over instead of actually fixing it.
This commit is contained in:
parent
8834a65e4c
commit
0170ec19c7
2 changed files with 18 additions and 11 deletions
22
lib/Lang.php
22
lib/Lang.php
|
@ -198,13 +198,17 @@ class Lang {
|
||||||
// otherwise start with the strings we already have if we're going from e.g. "fr" to "fr_ca"
|
// otherwise start with the strings we already have if we're going from e.g. "fr" to "fr_ca"
|
||||||
$strings[] = $this->strings;
|
$strings[] = $this->strings;
|
||||||
}
|
}
|
||||||
|
$loaded = array_diff($loaded, $files);
|
||||||
|
$toThrow = null;
|
||||||
|
while ($files) {
|
||||||
// read files in reverse order
|
// read files in reverse order
|
||||||
$files = array_reverse($files);
|
$file = array_pop($files);
|
||||||
foreach ($files as $file) {
|
|
||||||
if (!file_exists($this->path."$file.php")) {
|
if (!file_exists($this->path."$file.php")) {
|
||||||
throw new Lang\Exception("fileMissing", $file);
|
$toThrow = ["fileMissing", $file];
|
||||||
|
break;
|
||||||
} elseif (!is_readable($this->path."$file.php")) {
|
} elseif (!is_readable($this->path."$file.php")) {
|
||||||
throw new Lang\Exception("fileUnreadable", $file);
|
$toThrow = ["fileUnreadable", $file];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// we use output buffering in case the language file is corrupted
|
// we use output buffering in case the language file is corrupted
|
||||||
|
@ -216,16 +220,22 @@ class Lang {
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
}
|
}
|
||||||
if (!is_array($arr)) {
|
if (!is_array($arr)) {
|
||||||
throw new Lang\Exception("fileCorrupt", $file);
|
$toThrow = ["fileCorrupt", $file];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$strings[] = $arr;
|
$strings[] = $arr;
|
||||||
|
$loaded[] = $file;
|
||||||
}
|
}
|
||||||
// apply the results and return
|
// apply the results and return
|
||||||
$this->strings = call_user_func_array("array_replace_recursive", $strings);
|
$this->strings = array_replace_recursive(...$strings);
|
||||||
$this->loaded = $loaded;
|
$this->loaded = $loaded;
|
||||||
$this->locale = $this->wanted;
|
$this->locale = $this->wanted;
|
||||||
$this->synched = true;
|
$this->synched = true;
|
||||||
$this->formatter = null;
|
$this->formatter = null;
|
||||||
|
if ($toThrow) {
|
||||||
|
// if not all requested files could be loaded successfully, throw an exception
|
||||||
|
throw new Lang\Exception(...$toThrow);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,11 +43,8 @@ trait Setup {
|
||||||
return Glob::glob($this->path."*.php");
|
return Glob::glob($this->path."*.php");
|
||||||
});
|
});
|
||||||
$this->l = $this->l->get();
|
$this->l = $this->l->get();
|
||||||
// create a mock Lang object so as not to create a dependency loop
|
|
||||||
self::clearData(false);
|
self::clearData(false);
|
||||||
Arsse::$lang = $this->mock(Lang::class);
|
Arsse::$lang = $this->l;
|
||||||
Arsse::$lang->msg->returns("");
|
|
||||||
Arsse::$lang = Arsse::$lang->get();
|
|
||||||
// call the additional setup method if it exists
|
// call the additional setup method if it exists
|
||||||
if (method_exists($this, "setUpSeries")) {
|
if (method_exists($this, "setUpSeries")) {
|
||||||
$this->setUpSeries();
|
$this->setUpSeries();
|
||||||
|
|
Loading…
Reference in a new issue