Skip to content

Commit

Permalink
fix: Sanitize given api_host urls to not have a trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Dec 5, 2023
1 parent f4d0b90 commit 362d468
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/__tests__/posthog-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,15 @@ describe('posthog core', () => {
expect(given.overrides._send_request.mock.calls.length).toBe(0) // No outgoing requests
})

it('sanitizes api_host urls', () => {
given('config', () => ({
api_host: 'https://example.com/custom/',
}))
given.subject()

expect(given.lib.config.api_host).toBe('https://example.com/custom')
})

it('does not set __loaded_recorder_version flag if recording script has not been included', () => {
given('overrides', () => ({
__loaded_recorder_version: undefined,
Expand Down
2 changes: 2 additions & 0 deletions src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,8 @@ export class PostHog {
this.config.disable_persistence = this.config.disable_cookie
}

// We assume the api_host is without a trailing slash in most places throughout the codebase
this.config.api_host = this.config.api_host.replace(/\/$/, '')
this.persistence?.update_config(this.config)
this.sessionPersistence?.update_config(this.config)

Expand Down

0 comments on commit 362d468

Please sign in to comment.