{"record":{"id":"09e75ef415ffc20c","repo":"websockets/ws","slug":"unexpected-end-of-input","errorCode":null,"errorMessage":"Unexpected end of input","messagePattern":"Unexpected end of input","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"lib/extension.js","lineNumber":151,"sourceCode":"          mustUnescape = false;\n        }\n        push(params, paramName, value);\n        if (code === 0x2c) {\n          push(offers, extensionName, params);\n          params = Object.create(null);\n          extensionName = undefined;\n        }\n\n        paramName = undefined;\n        start = end = -1;\n      } else {\n        throw new SyntaxError(`Unexpected character at index ${i}`);\n      }\n    }\n  }\n\n  if (start === -1 || inQuotes || code === 0x20 || code === 0x09) {\n    throw new SyntaxError('Unexpected end of input');\n  }\n\n  if (end === -1) end = i;\n  const token = header.slice(start, end);\n  if (extensionName === undefined) {\n    push(offers, token, params);\n  } else {\n    if (paramName === undefined) {\n      push(params, token, true);\n    } else if (mustUnescape) {\n      push(params, paramName, token.replace(/\\\\/g, ''));\n    } else {\n      push(params, paramName, token);\n    }\n    push(offers, extensionName, params);\n  }\n\n  return offers;","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/websockets/ws/blob/c791e707eab3c13dd9a261d2479c3cc4a49a6fed/lib/extension.js#L133-L169","documentation":"Thrown by `extension.parse()` after the loop ends, when the final state is incomplete: `start === -1` (the parser was mid-way expecting another token but got end-of-input), `inQuotes === true` (an unterminated quoted value), or the last consumed character was a space/tab (trailing whitespace after a value that needed a separator or end). The message has no index because the failure is at EOF.","triggerScenarios":"Calling `extension.parse('permessage-deflate; key=\"unterminated')` (unclosed quote), `extension.parse('permessage-deflate;')` (trailing separator with nothing after), or `extension.parse('permessage-deflate; key=value ')` (trailing space).","commonSituations":"A peer truncates the header mid-value (MTU/proxy bug); a hand-edited header left unterminated; a trailing space from string concatenation.","solutions":["Terminate every quoted value with a closing `\"` and ensure the header ends with a complete token.","Remove trailing separators and trailing whitespace.","Catch the SyntaxError and close the connection with code 1002."],"exampleFix":"// before — unterminated quoted value\nconst offers = extension.parse('permessage-deflate; key=\"unterminated');\n\n// after — close the quote\nconst offers = extension.parse('permessage-deflate; key=\"terminated\"');","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"const { parse } = require('ws/lib/extension');\ntry {\n  const offers = parse(header);\n} catch (err) {\n  if (err instanceof SyntaxError) {\n    // Truncated header: unterminated quote, trailing separator, or trailing space.\n    abortHandshake(socket, 1002);\n    return;\n  }\n  throw err;\n}","preventionTips":["Terminate every quoted value with a closing `\"` and end the header on a complete token.","Strip trailing separators and whitespace before parsing.\n        ","Treat any 'Unexpected end of input' SyntaxError as a protocol error (close 1002)."],"tags":["websocket","protocol","parsing","header","rfc6455","sec-websocket-extensions"],"backgroundTag":null,"analyzedSha":"c791e707eab3c13dd9a261d2479c3cc4a49a6fed","analyzedAt":"2026-08-06T19:07:51.047Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}