{"record":{"id":"57bdebd706cdca93","repo":"AlistGo/alist","slug":"baidu-youth-locatedownload-url-is-empty","errorCode":null,"errorMessage":"baidu youth locatedownload url is empty","messagePattern":"baidu youth locatedownload url is empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"drivers/baidu_youth/util.go","lineNumber":364,"sourceCode":"\tif err != nil {\n\t\treturn \"\", \"\", \"\", err\n\t}\n\tfor _, listedFile := range files {\n\t\tif listedFile.Path != file.GetPath() {\n\t\t\tcontinue\n\t\t}\n\t\tfileID := strconv.FormatInt(listedFile.FsId, 10)\n\t\tif listedFile.Path != \"\" && fileID != \"\" && listedFile.Md5 != \"\" {\n\t\t\treturn listedFile.Path, fileID, listedFile.Md5, nil\n\t\t}\n\t\treturn \"\", \"\", \"\", fmt.Errorf(\"baidu youth list metadata incomplete for %s\", file.GetPath())\n\t}\n\treturn \"\", \"\", \"\", errs.NewErr(errs.ObjectNotFound, \"baidu youth list metadata not found: %s\", file.GetPath())\n}\n\nfunc normalizeLocatedownloadURL(rawURL string) (string, error) {\n\tif rawURL == \"\" {\n\t\treturn \"\", fmt.Errorf(\"baidu youth locatedownload url is empty\")\n\t}\n\tif !strings.Contains(rawURL, \"response-cache-control=\") {\n\t\tsep := \"&\"\n\t\tif !strings.Contains(rawURL, \"?\") {\n\t\t\tsep = \"?\"\n\t\t}\n\t\trawURL += sep + \"response-cache-control=private\"\n\t}\n\treturn rawURL, nil\n}\n\nfunc (d *BaiduYouth) getMediaInfoDLink(ctx context.Context, file model.Obj) (string, error) {\n\tpath, fileID, _, err := d.resolveDownloadMeta(ctx, file)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tvar resp MediaInfoResp","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/baidu_youth/util.go#L346-L382","documentation":"Defensive check in normalizeLocatedownloadURL (drivers/baidu_youth/util.go:364): it refuses to process an empty URL string. It only fires if a caller passes '' — the upstream callers (getLocatedownloadURL) already check resp.URL themselves, so seeing it means an internal contract violation or a new call path skipping the check.","triggerScenarios":"Directly calling normalizeLocatedownloadURL with an empty string; a future code path obtaining the URL from a different API that returned an empty field without checking first.","commonSituations":"Refactors adding new download URL sources; unit tests exercising the normalizer with zero values.","solutions":["Check the URL is non-empty at the source (right after the API response) before normalizing","Reuse getLocateDownloadURL, which performs the empty check on resp.URL, instead of calling the normalizer directly"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if rawURL == \"\" {\n    return \"\", fmt.Errorf(\"locatedownload returned no url for %s\", file.GetPath())\n}\nreturn normalizeLocatedownloadURL(rawURL)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the public getLocateDownloadURL flow; it already validates resp.URL","In tests, feed the normalizer non-empty fixtures unless testing the guard itself"],"tags":["baidu-youth","internal","validation","go"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}