-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: The dialogue function of the layout interface has an incorrect r… #4529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| MsgError(res.node.properties?.stepName + ` ${t('workflow.node')},` + err_message) | ||
| } else { | ||
| const keys = Object.keys(err_message) | ||
| MsgError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code contains several issues and areas for improvement:
-
Variable Reassignment: The variable
urlParamsis redefined within a conditional block inside thecomputeddefinition, which can lead to unexpected behavior. -
URL Concatenation: There are multiple instances where URLs are concatenated using string operators directly, without ensuring proper escaping or handling of special characters. This could potentially introduce security vulnerabilities if not properly managed.
-
Empty Strings in Conditional Statements: In some places, conditions involve checking empty strings using
!value, which might not be intuitive. Consider usingBoolean(value)instead for clearer logic. -
Error Message Handling: Error messages should be displayed correctly, especially when dealing with complex error objects like those returned from API calls.
-
Unused Variables: Some variables (
detail.value) appear unused and could be removed to simplify the code.
Here's a revised version of the code addressing these points:
const detail = ref(null);
const saveTime = ref(new Date());
// Ensure URL parameters are safe before concatenating them
function safeStringify(input) {
return JSON.stringify(input).replace(/"/g, '\\"').replace(/\n/gi, "\\n");
}
const urlParams = computed(() => {
const apiUrlParams = mapToUrlParams(apiInputParams.value) || {}
const queryPart = Object.entries(apiUrlParams)
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
.join('&');
return queryPart.length > 0 ? `?${queryPart}` : '';
});
const shareUrl = computed(() => {
let baseURL;
if (window.MaxKB) {
baseURL = window.MaxKB.chatPrefix;
} else {
// Provide default base URL if MaxKB is undefined or null
baseURL = '/chat/';
}
return baseURL + detail.value?.access_token + urlParams.value;
});
function back() {
history.back();
}
async function publish() {
try {
const res = await fetch("https://api.maxkb.com/publish-workflow", {
method: "POST",
headers: {
ContentType: "application/json; charset=utf-8",
},
body: JSON.stringify({
workflowId: detail.value.id,
input: apiInputParams.value,
}),
});
if (!res.ok) {
throw new Error(`Request failed with status ${res.status}`);
}
const data = await res.json();
// Handle success response
} catch (error) {
console.error('Failed to publish:', error);
MsgError(t('workflow.common.networkError'));
}
}Key Changes:
- Safe Stringification: Added
safeStringifyhelper function to safely stringify objects into query parameters. - URL Safe Encoding: Ensured parameter values are safely encoded for use in URLs.
- Base URL Logic Check: Implemented a simple check to ensure a valid base URL is used, providing a fallback if necessary.
- Removed Unnecessary Variable Assignment: Removed unnecessary reassignments of
urlParams.
These changes improve the robustness and maintainability of the code.
…edirect path
What this PR does / why we need it?
Summary of your change
Please indicate you've done the following: