diff --git a/plugin.json b/plugin.json index 9690b00..bc5f9d0 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "id": "lyrics_sync", "name": "Lyrics Sync", - "version": "1.0.1", + "version": "1.0.2", "private": false, "nav": { "label": "Lyrics Sync", diff --git a/routes.py b/routes.py index 19e42b4..a70dff7 100644 --- a/routes.py +++ b/routes.py @@ -3,6 +3,7 @@ import json import os from pathlib import Path, PurePosixPath, PureWindowsPath +from urllib.parse import quote from fastapi import FastAPI from fastapi.responses import JSONResponse, Response @@ -219,7 +220,13 @@ def ls_align(data: dict): 502, ) - result = resp.json() + try: + result = resp.json() + except ValueError: + return JSONResponse( + {"error": "Alignment server returned a malformed response"}, + 502, + ) if "error" in result: return JSONResponse( {"error": f"Alignment failed: {result['error']}"}, @@ -260,11 +267,22 @@ def ls_export(data: dict): safe_name = f"{artist} - {title}".strip(" -") or "lyrics" safe_name = safe_name.replace("/", "_").replace("\\", "_") + # Quote-escape for the legacy `filename=` fallback, and provide an + # RFC 5987 `filename*=` form so non-ASCII / quote characters in + # title-artist can't corrupt or break out of the header value. + # The `\` escape is a no-op today (safe_name already stripped `\` + # above) but guards this line if that stripping ever changes. + ascii_name = safe_name.replace("\\", "\\\\").replace('"', '\\"') + encoded_name = quote(f"{safe_name}.lrc", safe="") + return Response( content=lrc, media_type="text/plain", headers={ - "Content-Disposition": f'attachment; filename="{safe_name}.lrc"', + "Content-Disposition": ( + f'attachment; filename="{ascii_name}.lrc"; ' + f"filename*=UTF-8''{encoded_name}" + ), }, )