mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-30 20:44:18 +02:00
Auto-fix JSON comments and trailing commas for HTTP request bodies
Add a per-request "Automatically Fix JSON" toggle (default: on) that strips comments and trailing commas before sending HTTP requests. When disabled, comments are sent as-is and the editor linter flags them as errors. - New JsonBodyEditor component with settings dropdown and dismissible banner - Configurable JSON linter (allowComments/allowTrailingCommas) via lintExtension prop - strip_trailing_commas pass in Rust strip_json_comments pipeline - Fix JSON formatter pulling standalone comments onto previous comma line - Add get_bool_map helper, maybe_strip_json_comments, and related tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
30
src-web/lib/jsonComments.ts
Normal file
30
src-web/lib/jsonComments.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Simple heuristic to detect if a string likely contains JSON/JSONC comments.
|
||||
* Checks for // and /* patterns that are NOT inside double-quoted strings.
|
||||
* Used for UI hints only — doesn't need to be perfect.
|
||||
*/
|
||||
export function textLikelyContainsJsonComments(text: string): boolean {
|
||||
let inString = false;
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
const ch = text[i];
|
||||
if (inString) {
|
||||
if (ch === '"') {
|
||||
inString = false;
|
||||
} else if (ch === '\\') {
|
||||
i++; // skip escaped char
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (ch === '"') {
|
||||
inString = true;
|
||||
continue;
|
||||
}
|
||||
if (ch === '/' && i + 1 < text.length) {
|
||||
const next = text[i + 1];
|
||||
if (next === '/' || next === '*') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user