fix: cleanr body and formData in curl import

This commit is contained in:
Udhay-Adithya
2025-09-27 18:13:35 +05:30
parent 86f35755eb
commit 34f2ae6178

View File

@@ -416,15 +416,18 @@ class ChatViewmodel extends StateNotifier<ChatState> {
final withEnvUrl = await _maybeSubstituteBaseUrl(url, baseUrl); final withEnvUrl = await _maybeSubstituteBaseUrl(url, baseUrl);
if (action.field == 'apply_to_selected') { if (action.field == 'apply_to_selected') {
if (requestId == null) return; if (requestId == null) return;
final replacingBody =
(formFlag || formData.isNotEmpty) ? '' : (body ?? '');
final replacingFormData =
formData.isEmpty ? const <FormDataModel>[] : formData;
collection.update( collection.update(
method: method, method: method,
url: withEnvUrl, url: withEnvUrl,
headers: headers, headers: headers,
isHeaderEnabledList: List<bool>.filled(headers.length, true), isHeaderEnabledList: List<bool>.filled(headers.length, true),
body: body, body: replacingBody,
bodyContentType: bodyContentType, bodyContentType: bodyContentType,
formData: formData.isEmpty ? null : formData, formData: replacingFormData,
// Wipe existing parameters and authentication to ensure clean state
params: const [], params: const [],
isParamEnabledList: const [], isParamEnabledList: const [],
authModel: null, authModel: null,
@@ -895,14 +898,19 @@ class ChatViewmodel extends StateNotifier<ChatState> {
final withEnvUrl = await _maybeSubstituteBaseUrl(url, baseUrl); final withEnvUrl = await _maybeSubstituteBaseUrl(url, baseUrl);
if (action.field == 'apply_to_selected') { if (action.field == 'apply_to_selected') {
if (requestId == null) return; if (requestId == null) return;
// Replacement semantics: ensure previous body/formData are cleared if absent in cURL
final replacingBody =
(formFlag || formData.isNotEmpty) ? '' : (body ?? '');
final replacingFormData =
formData.isEmpty ? const <FormDataModel>[] : formData;
collection.update( collection.update(
method: method, method: method,
url: withEnvUrl, url: withEnvUrl,
headers: headers, headers: headers,
isHeaderEnabledList: List<bool>.filled(headers.length, true), isHeaderEnabledList: List<bool>.filled(headers.length, true),
body: body, body: replacingBody,
bodyContentType: bodyContentType, bodyContentType: bodyContentType,
formData: formData.isEmpty ? null : formData, formData: replacingFormData,
// Wipe existing parameters and authentication to ensure clean state // Wipe existing parameters and authentication to ensure clean state
params: const [], params: const [],
isParamEnabledList: const [], isParamEnabledList: const [],