|
@@ -4,7 +4,6 @@ namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Console\Command;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
-use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
|
|
class FixDoubleEncodedOptions extends Command
|
|
class FixDoubleEncodedOptions extends Command
|
|
|
{
|
|
{
|
|
@@ -137,9 +136,10 @@ class FixDoubleEncodedOptions extends Command
|
|
|
$secondDecode = json_decode($decoded, true);
|
|
$secondDecode = json_decode($decoded, true);
|
|
|
|
|
|
|
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
|
- // 解码失败,可能是 LaTeX 中的反斜杠问题(如 \times, \frac 等)
|
|
|
|
|
- // 尝试将单个反斜杠转义为双反斜杠后再解码
|
|
|
|
|
- $escapedDecoded = $this->escapeLatexBackslashes($decoded);
|
|
|
|
|
|
|
+ // 解码失败,可能是 LaTeX 中的反斜杠问题
|
|
|
|
|
+ // 问题:\times 中的 \t 是合法 JSON 转义(tab),\frac 中的 \f 也是(form feed)
|
|
|
|
|
+ // 解决:第一次解码后,所有反斜杠都是 LaTeX 的,全部转义为双反斜杠
|
|
|
|
|
+ $escapedDecoded = str_replace('\\', '\\\\', $decoded);
|
|
|
$secondDecode = json_decode($escapedDecoded, true);
|
|
$secondDecode = json_decode($escapedDecoded, true);
|
|
|
|
|
|
|
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
@@ -173,19 +173,4 @@ class FixDoubleEncodedOptions extends Command
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 转义 LaTeX 公式中的反斜杠
|
|
|
|
|
- * 将非 JSON 转义序列的反斜杠转义为双反斜杠
|
|
|
|
|
- */
|
|
|
|
|
- private function escapeLatexBackslashes(string $str): string
|
|
|
|
|
- {
|
|
|
|
|
- // JSON 合法的转义序列: \", \\, \/, \b, \f, \n, \r, \t, \uXXXX
|
|
|
|
|
- // 其他的反斜杠(如 LaTeX 的 \times, \frac, \sqrt 等)需要转义
|
|
|
|
|
-
|
|
|
|
|
- // 使用回调函数处理每个反斜杠
|
|
|
|
|
- return preg_replace_callback('/\\\\(?!["\\\\/bfnrt]|u[0-9a-fA-F]{4})/', function ($match) {
|
|
|
|
|
- // 将单个反斜杠替换为双反斜杠
|
|
|
|
|
- return '\\' . $match[0];
|
|
|
|
|
- }, $str);
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|