{"record":{"id":"26dce003a0a661cc","repo":"getgrav/grav","slug":"failed-to-rename-file-plugin-admin-bad-filename","errorCode":null,"errorMessage":"Failed to rename file: PLUGIN_ADMIN.BAD_FILENAME","messagePattern":"Failed to rename file: PLUGIN_ADMIN\\.BAD_FILENAME","errorType":"exception","errorClass":"RuntimeException","httpStatus":400,"severity":"error","filePath":"system/src/Grav/Common/Media/Traits/MediaUploadTrait.php","lineNumber":395,"sourceCode":"     * Rename file inside the media collection.\n     *\n     * @param string $from\n     * @param string $to\n     * @param array|null $settings\n     */\n    public function renameFile(string $from, string $to, ?array $settings = null): void\n    {\n        // Add the defaults to the settings.\n        $settings = $this->getUploadSettings($settings);\n        $filesystem = Filesystem::getInstance(false);\n\n        // This method had no filename validation at all. It has no callers in core\n        // today, but it is part of the public MediaUploadInterface, so a plugin can\n        // reach it directly. Both names are checked the same way deleteFile() does.\n        if (!$this->checkFilepath($from) || !Utils::checkFilename($filesystem->basename($from))\n            || !$this->checkFilepath($to) || !Utils::checkFilename($filesystem->basename($to))) {\n            // TODO: translate error message\n            throw new RuntimeException('Failed to rename file: ' . $this->translate('PLUGIN_ADMIN.BAD_FILENAME'), 400);\n        }\n\n        $path = $settings['destination'] ?? $this->getPath();\n        if (!$path) {\n            // TODO: translate error message\n            throw new RuntimeException('Failed to rename file: Bad destination', 400);\n        }\n\n        /** @var UniformResourceLocator $locator */\n        $locator = $this->getGrav()['locator'];\n        $locator->clearCache();\n\n        // Get base name of the file.\n        $pathname = $filesystem->pathname($from);\n\n        // Remove @2x, @3x and .meta.yaml\n        [$base, $ext,,] = $this->getFileParts($filesystem->basename($from));\n        $from = \"{$pathname}{$base}.{$ext}\";","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/getgrav/grav/blob/6040efed04efa69b8209448ed81308e7c24147c2/system/src/Grav/Common/Media/Traits/MediaUploadTrait.php#L377-L413","documentation":"Error \"Failed to rename file: PLUGIN_ADMIN.BAD_FILENAME\" thrown in getgrav/grav.","triggerScenarios":"Thrown at system/src/Grav/Common/Media/Traits/MediaUploadTrait.php:395 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6040efed04efa69b8209448ed81308e7c24147c2","analyzedAt":"2026-08-17T05:07:31.593Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}