Skip to content
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

fix: Handle API URL with or without trailing slash #288

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

kyle-ssg
Copy link
Member

@kyle-ssg kyle-ssg commented Jan 22, 2025

Ensures that the flagsmith base url has a single trailing /. Whilst I considered using JavaScript's built in URL API, there's a chance that a polyfil would be needed to guarantee exact same behaviour so this seemed far less risky.

@kyle-ssg kyle-ssg linked an issue Jan 22, 2025 that may be closed by this pull request
Copy link
Member

@rolodato rolodato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick turnaround! I would prefer if we apply my suggestion but I can live without it.

@@ -0,0 +1,3 @@
export function ensureTrailingSlash(str: string): string {
return str.replace(/\/+$/, '') + '/';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return str.replace(/\/+$/, '') + '/';
return str.endsWith('/') ? str : str + '/';

A URL such as https://flagsmith.example.com//// is technically distinct from https://flagsmith.example.com/, and this regex would remove all trailing slashes except one. I know this sounds like extreme bikeshedding but it's closer in line to what we do in other SDKs, e.g. Go, .NET, Node.js, Ruby

@rolodato rolodato changed the title fix: Sanitise api url fix: Handle API URLs with or without trailing slashes Jan 22, 2025
@rolodato rolodato changed the title fix: Handle API URLs with or without trailing slashes fix: Handle API URL with or without trailing slash Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle API URL without trailing slash
3 participants