Back to all reviewers

API input validation

logseq/logseq
Based on 3 comments
TypeScript

When working with APIs, always validate inputs beyond basic format checking to ensure semantic correctness and handle edge cases properly. Simple constructor calls or basic format validation may accept invalid or unexpected inputs that could cause issues downstream.

API TypeScript

Reviewer Prompt

When working with APIs, always validate inputs beyond basic format checking to ensure semantic correctness and handle edge cases properly. Simple constructor calls or basic format validation may accept invalid or unexpected inputs that could cause issues downstream.

For URL validation, don’t rely solely on constructor success - verify the parsed components meet your requirements:

const isValidURL = (url: string) => {
  try {
    const parsedUrl = new URL(url)
    return parsedUrl.host && ['http:', 'https:'].includes(parsedUrl.protocol)
  } catch {
    return false
  }
}

Similarly, when choosing API methods, understand their behavior and constraints rather than assuming functionality. Test different approaches empirically when stability is critical, and be prepared to revert changes if they break expected behavior. Always validate that your API usage works as intended across different scenarios and edge cases.

3
Comments Analyzed
TypeScript
Primary Language
API
Category

Source Discussions