10 lines
691 B
TypeScript
10 lines
691 B
TypeScript
|
|
// CSV field สำหรับ export สรุปหมายเหตุ (F16/D3) — route export-csv ใช้ร่วม
|
||
|
|
|
||
|
|
/** ครอบ field ด้วย double quote (RFC 4180) แล้ว escape `"` เป็น `""`
|
||
|
|
* FIX-6: field ที่ขึ้นต้นด้วย = + - @ หรือ TAB/CR ต้องนำหน้าด้วย '
|
||
|
|
* ก่อนครอบ quote — กัน Excel/Sheets ตีความค่าเป็นสูตรเมื่อเปิดไฟล์ (OWASP CSV Injection) */
|
||
|
|
export function csvField(v: string): string {
|
||
|
|
const guarded = /^[=+\-@\t\r]/.test(v) ? `'${v}` : v;
|
||
|
|
return `"${guarded.replace(/"/g, '""')}"`;
|
||
|
|
}
|