Skip to content

[BUG] The code uses rstrip("api") to drop a trailing "/api" from a base URL/host. #1203

@CedricHwong

Description

@CedricHwong

🐛 Bug description (make it clear to everyone)

The code uses rstrip("api") to drop a trailing "/api" from a base URL/host.
But rstrip treats its argument as a set of characters ({'a','p','i'}) and strips all trailing occurrences of those chars.
This mutilates valid hosts/paths.
Example:

"www.example.ai".rstrip("api")  # -> "www.example."

🧑‍💻 Steps to reproduce

  1. Set a host/base URL ending with .ai (or anything ending in a, p, or i), e.g.:
    base = "https://www.example.ai/api"
  2. Run the logic that normalizes/removes the "/api" suffix (e.g., login/init flow).
  3. Observe the resulting host string becomes:
    https://www.example.
    
    (the trailing ai is incorrectly stripped)

👾 Expected result

  • Remove the suffix only if the string ends with the exact "/api" once.
  • Do not strip characters from legitimate domain endings such as .ai, .app, etc.

Examples:

  • "https://www.example.ai/api""https://www.example.ai"
  • "https://www.example.ai" → unchanged

🚑 Any additional info (screenshots, code, logs)

Minimal proof:

>>> "www.example.ai".rstrip("api")
'www.example.'
>>> "https://www.example.ai/api".rstrip("api")
'https://www.example.'

🔧 Suggested fix

🧭 Environment

  • SwanLab Version: v0.6.7
  • Platform/OS: Ubuntu 22.04
  • Python Version: 3.10.12

Reported by Kingdee Cloud Team 💼

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions