From cadfc41c3b403c7d6b259948c126f0c3dcfdb046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Antonio=20P=C3=A9rez?= Date: Thu, 26 Feb 2026 22:54:01 +0100 Subject: [PATCH] fix: URL-encode Target header for non-ASCII heading names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Local REST API OpenAPI spec states that the Target header value "can be URL-Encoded and *must* be URL-Encoded if it includes non-ASCII characters." However, patch_vault_file and patch_active_file were passing the Target header value as-is, causing HTTP header validation errors for any heading containing accented characters (e.g., "Información", "Método") or special characters (e.g., em-dash). This commit: - Applies encodeURIComponent() to the Target header in both patch_active_file and patch_vault_file - Applies the same encoding to Target-Delimiter header - Changes obsidian imports in plugin-templater.ts to type-only imports, since they are only used in type positions (interfaces/type aliases) Co-Authored-By: Claude Opus 4.6 --- packages/mcp-server/src/features/local-rest-api/index.ts | 8 ++++---- packages/shared/src/types/plugin-templater.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/mcp-server/src/features/local-rest-api/index.ts b/packages/mcp-server/src/features/local-rest-api/index.ts index 37a1424..16f542c 100644 --- a/packages/mcp-server/src/features/local-rest-api/index.ts +++ b/packages/mcp-server/src/features/local-rest-api/index.ts @@ -98,12 +98,12 @@ export function registerLocalRestApiTools(tools: ToolRegistry, server: Server) { const headers: Record = { Operation: args.operation, "Target-Type": args.targetType, - Target: args.target, + Target: encodeURIComponent(args.target), "Create-Target-If-Missing": "true", }; if (args.targetDelimiter) { - headers["Target-Delimiter"] = args.targetDelimiter; + headers["Target-Delimiter"] = encodeURIComponent(args.targetDelimiter); } if (args.trimTargetWhitespace !== undefined) { headers["Trim-Target-Whitespace"] = String(args.trimTargetWhitespace); @@ -359,12 +359,12 @@ export function registerLocalRestApiTools(tools: ToolRegistry, server: Server) { const headers: HeadersInit = { Operation: args.operation, "Target-Type": args.targetType, - Target: args.target, + Target: encodeURIComponent(args.target), "Create-Target-If-Missing": "true", }; if (args.targetDelimiter) { - headers["Target-Delimiter"] = args.targetDelimiter; + headers["Target-Delimiter"] = encodeURIComponent(args.targetDelimiter); } if (args.trimTargetWhitespace !== undefined) { headers["Trim-Target-Whitespace"] = String(args.trimTargetWhitespace); diff --git a/packages/shared/src/types/plugin-templater.ts b/packages/shared/src/types/plugin-templater.ts index 5857aae..861077a 100644 --- a/packages/shared/src/types/plugin-templater.ts +++ b/packages/shared/src/types/plugin-templater.ts @@ -1,6 +1,6 @@ -import { +import type { App, - type MarkdownPostProcessorContext, + MarkdownPostProcessorContext, TAbstractFile, TFile, TFolder,