fix(quotesdb): use char count for reason validation, remove duplicate CountRow in d1

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
main
Elijah Voigt 3 months ago
parent f8c6dcb832
commit 6c2ee37feb

@ -684,17 +684,12 @@ impl QuoteRepository for D1Repository {
/// with the given `quote_id` exists. /// with the given `quote_id` exists.
async fn create_report(&self, quote_id: &str, reason: Option<&str>) -> Result<(), DbError> { async fn create_report(&self, quote_id: &str, reason: Option<&str>) -> Result<(), DbError> {
// Step 1: verify the quote exists. // Step 1: verify the quote exists.
#[derive(serde::Deserialize)]
struct ExistsRow {
count: i64,
}
let exists_row = self let exists_row = self
.db .db
.prepare("SELECT COUNT(*) AS count FROM quotes WHERE id = ?1") .prepare("SELECT COUNT(*) AS count FROM quotes WHERE id = ?1")
.bind(&[JsValue::from_str(quote_id)]) .bind(&[JsValue::from_str(quote_id)])
.map_err(|e| DbError::Internal(e.to_string()))? .map_err(|e| DbError::Internal(e.to_string()))?
.first::<ExistsRow>(None) .first::<CountRow>(None)
.await .await
.map_err(|e| DbError::Internal(e.to_string()))?; .map_err(|e| DbError::Internal(e.to_string()))?;

@ -565,7 +565,7 @@ async fn report_handler(
let reason = body.and_then(|Json(input)| input.reason); let reason = body.and_then(|Json(input)| input.reason);
// Validate reason length — enforced here before the DB call. // Validate reason length — enforced here before the DB call.
if reason.as_deref().map(|r| r.len()).unwrap_or(0) > 256 { if reason.as_deref().map(|r| r.chars().count()).unwrap_or(0) > 256 {
return error_response( return error_response(
StatusCode::BAD_REQUEST, StatusCode::BAD_REQUEST,
"reason must be at most 256 characters", "reason must be at most 256 characters",

Loading…
Cancel
Save