Skip to content

you're using .trim() on something that might be undefined #49

@johndeighan

Description

@johndeighan

In util.civet, there's this:

/**
handler to source
*/
hToS := (h: Handler | undefined): string ->
  return "" unless h?

  if typeof h is "object" and "f" in h // functional handler
    // Function handler type annotation
    t := "t" in h ? ` :: ${h.t.trim()}` : ""
    // Restore indentation
    `${t} ->\n${h.f.replace(/^|\n/g, "$&    ")}`
  else // structural handler
    " -> " + structuralToSource(h)

The problem is in the assignment to variable t. You're checking that t is a key in h, but that doesn't guarantee that h.t is defined. In fact, I'd check for (typeof h.t == 'string') to be sure it's not only defined, but is a string. I'm not sure why whatever version of TypeScript you developed this under didn't catch that, but it's a simple fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions