Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

…edirect path

What this PR does / why we need it?

Summary of your change

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 17, 2025

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.

Details

Instructions 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.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 17, 2025

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@shaohuzhang1 shaohuzhang1 merged commit d8e03e6 into v2 Dec 17, 2025
2 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v@fix_chat branch December 17, 2025 05:42
MsgError(res.node.properties?.stepName + ` ${t('workflow.node')},` + err_message)
} else {
const keys = Object.keys(err_message)
MsgError(
Copy link
Contributor Author

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:

  1. Variable Reassignment: The variable urlParams is redefined within a conditional block inside the computed definition, which can lead to unexpected behavior.

  2. 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.

  3. Empty Strings in Conditional Statements: In some places, conditions involve checking empty strings using !value, which might not be intuitive. Consider using Boolean(value) instead for clearer logic.

  4. Error Message Handling: Error messages should be displayed correctly, especially when dealing with complex error objects like those returned from API calls.

  5. 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 safeStringify helper 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.

shaohuzhang1 added a commit that referenced this pull request Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants