Skip to content

hackernews example: add typed Post interface, fix sql injection#31

Merged
cs01 merged 1 commit intomainfrom
hn-example-fixes
Feb 22, 2026
Merged

hackernews example: add typed Post interface, fix sql injection#31
cs01 merged 1 commit intomainfrom
hn-example-fixes

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Feb 22, 2026

Summary

  • Add Post interface and parsePost() helper to replace brittle positional indexing (parts[0]...parts[3]) with typed field access (post.id, post.title, post.url, post.points)
  • Fix SQL injection in upvote handler by switching from string concatenation to parameterized query (sqlite.exec(db, "...WHERE id = ?", [idStr]))
  • Pipe-delimited parsing is isolated to parsePost() — when a first-class sqlite.allObjects() API lands, only that one function changes

Test plan

  • npm run build — TypeScript compiles cleanly
  • npm test — all compiler tests pass (changes are example-only, no compiler code touched)
  • Manual: chad build examples/hackernews/app.ts && ./app — serves correctly, upvote works

@cs01 cs01 merged commit a040a27 into main Feb 22, 2026
14 checks passed
@cs01 cs01 deleted the hn-example-fixes branch February 22, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant