toon-format/toon · error · SyntaxError

Unexpected characters after closing quote

Error message

Unexpected characters after closing quote

What it means

A quoted string token had a valid closing quote, but characters remained after it (e.g. `"abc"xyz`). TOON requires a quoted string token to end exactly at its closing quote, so any trailing characters make the token invalid and parsing stops with a SyntaxError.

Source

Thrown at packages/toon/src/decode/parser.ts:479

    const parsedNumber = Number.parseFloat(trimmedToken)
    return Object.is(parsedNumber, -0) ? 0 : parsedNumber
  }

  return trimmedToken
}

export function parseStringLiteral(token: string): string {
  const trimmedToken = trimSpaces(token)

  if (trimmedToken.startsWith(DOUBLE_QUOTE)) {
    const closingQuoteIndex = findClosingQuote(trimmedToken, 0)

    if (closingQuoteIndex === -1) {
      throw new SyntaxError('Unterminated string: missing closing quote')
    }

    if (closingQuoteIndex !== trimmedToken.length - 1) {
      throw new SyntaxError('Unexpected characters after closing quote')
    }

    const content = trimmedToken.slice(1, closingQuoteIndex)
    return unescapeString(content)
  }

  return trimmedToken
}

export function parseUnquotedKey(content: string, start: number): { key: string, end: number } {
  // A raw scan would cut `a "b:c" d: 1` at the quoted colon and split the key in two.
  const colonIndex = findUnquotedChar(content, COLON, start)

  if (colonIndex === -1) {
    throw new SyntaxError('Missing colon after key')
  }

  return { key: trimSpaces(content.slice(start, colonIndex)), end: colonIndex + 1 }

View on GitHub (pinned to 604eac266e)

Solutions

  1. Remove the extra characters after the closing quote so the token is exactly `"..."`
  2. Separate the quoted string and the following value with the proper delimiter (comma/semicolon/tab as per the document)
  3. Quote only where necessary — unquoted plain values avoid this class of error
  4. Generate output with toon.encode instead of hand-writing quoted tokens

Example fix

// before
name: "Alice" Smith
// after
name: "Alice"
Defensive patterns

Strategy: try-catch

Validate before calling

function noTrailingAfterQuotes(text) {
  return !/["'][^"']*"[^,;\t\]}:\n]/.test(text)
}

Try / catch

try {
  const value = toon.decode(text)
} catch (err) {
  if (err instanceof SyntaxError && err.message.includes('after closing quote')) {
    // strip/fix trailing characters after quoted tokens
  } else throw err
}

Prevention

When it happens

Trigger: Decoding input where a quoted token has trailing text — e.g. `name: "Alice" Smith`, array rows like `["a"b,2]`, or a header field `"col"1`. Reached via parseStringLiteral when closingQuoteIndex !== trimmedToken.length - 1.

Common situations: Concatenating quoted values without delimiters; hand-editing strings and leaving stray characters; generator bugs that append suffixes (like an index) after the quote; copy-paste merging two tokens together.

Related errors


AI-assisted analysis of toon-format/toon@604eac266e (2026-08-31). Data as JSON: /api/errors/b5f6345504b97f19. Report an issue: GitHub.