{"record":{"id":"0c8ef6dcd3a50ffa","repo":"evanw/esbuild","slug":"could-not-decode-percent-escaped-data-s","errorCode":null,"errorMessage":"could not decode percent-escaped data: %s","messagePattern":"could not decode percent-escaped data: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/resolver/dataurl.go","lineNumber":73,"sourceCode":"\tdefault:\n\t\treturn MIMETypeUnsupported\n\t}\n}\n\nfunc (parsed DataURL) DecodeData() (string, error) {\n\t// Try to read base64 data\n\tif parsed.isBase64 {\n\t\tbytes, err := base64.StdEncoding.DecodeString(parsed.data)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"could not decode base64 data: %s\", err.Error())\n\t\t}\n\t\treturn string(bytes), nil\n\t}\n\n\t// Try to read percent-escaped data\n\tcontent, err := url.PathUnescape(parsed.data)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"could not decode percent-escaped data: %s\", err.Error())\n\t}\n\treturn content, nil\n}\n","sourceCodeStart":55,"sourceCodeEnd":77,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/internal/resolver/dataurl.go#L55-L77","documentation":"When esbuild resolves a data: URL without the ;base64 flag, it calls url.PathUnescape on the payload to decode percent-encoded characters. This error fires when the data contains malformed percent-escape sequences such as a lone '%' or '%ZZ' (non-hex digits after the percent sign).","triggerScenarios":"Importing a data: URL (without ;base64) containing a percent sign not followed by two hex digits, e.g. 'data:text/javascript,console.log(50%)'.","commonSituations":"Data URLs with literal percent signs (like in math expressions or formatting), truncated percent escapes, or data that was not properly URL-encoded.","solutions":["Ensure every '%' in the data URL is followed by exactly two hex digits (e.g. '%25' for a literal percent sign)","Generate data URLs using encodeURIComponent or encodeURI to produce valid percent escapes","Use base64 encoding instead of percent-encoding if the data contains many special characters"],"exampleFix":"// before\nimport x from 'data:text/javascript,console.log(50%)'\n// after\nimport x from 'data:text/javascript,console.log(50%25)'","handlingStrategy":"validation","validationCode":"function makeDataUrl(mimeType, content) {\n  // encodeURIComponent produces valid percent-escapes\n  return `data:${mimeType},${encodeURIComponent(content)}`\n}\nfunction isValidPercentEncoding(str) {\n  return !/%[^0-9a-fA-F]|%[0-9a-fA-F][^0-9a-fA-F]/.test(str)\n}\nconst url = makeDataUrl('text/javascript', 'export default 1')\n// safe to import","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use encodeURIComponent or encodeURI to produce data URL payloads","Manually check for stray '%' not followed by two hex digits in data URLs","Use base64 encoding if the data contains many percent signs"],"tags":["esbuild","data-url","percent-encoding","resolver"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}