From c09995a0c24cbdf2170580991b5d76c6436e9c43 Mon Sep 17 00:00:00 2001 From: siyuniu-ms <123212536+siyuniu-ms@users.noreply.github.com> Date: Fri, 13 Oct 2023 16:41:05 -0700 Subject: [PATCH] [main] remove double slash for endPointUrl (#2174) --- shared/AppInsightsCommon/src/ConnectionStringParser.ts | 6 +++++- tools/applicationinsights-web-snippet/src/snippet.ts | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/shared/AppInsightsCommon/src/ConnectionStringParser.ts b/shared/AppInsightsCommon/src/ConnectionStringParser.ts index 5dc88cab9..f6ba75aad 100644 --- a/shared/AppInsightsCommon/src/ConnectionStringParser.ts +++ b/shared/AppInsightsCommon/src/ConnectionStringParser.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -import { arrReduce, objKeys } from "@microsoft/applicationinsights-core-js"; +import { arrReduce, objKeys, strEndsWith } from "@microsoft/applicationinsights-core-js"; import { DEFAULT_BREEZE_ENDPOINT } from "./Constants"; import { ConnectionString, ConnectionStringKey } from "./Interfaces/ConnectionString"; @@ -37,6 +37,10 @@ export function parseConnectionString(connectionString?: string): ConnectionStri // apply the default endpoints result.ingestionendpoint = result.ingestionendpoint || DEFAULT_BREEZE_ENDPOINT; + + if (strEndsWith(result.ingestionendpoint, "/")) { + result.ingestionendpoint = result.ingestionendpoint.slice(0,-1); + } } return result; diff --git a/tools/applicationinsights-web-snippet/src/snippet.ts b/tools/applicationinsights-web-snippet/src/snippet.ts index ecba94766..9d9e2ac87 100644 --- a/tools/applicationinsights-web-snippet/src/snippet.ts +++ b/tools/applicationinsights-web-snippet/src/snippet.ts @@ -96,6 +96,9 @@ declare var cfg:ISnippetConfig; let conString = _parseConnectionString(); let iKey = conString[strConStringIKey] || aiConfig[strInstrumentationKey] || strEmpty; let ingest = conString[strIngestionendpoint]; + if (ingest && ingest.slice(-1) === "/"){ + ingest = ingest.slice(0,-1); + } let endpointUrl = ingest ? ingest + "/v2/track" : aiConfig.endpointUrl; // only add /v2/track when from connectionstring let message = "SDK LOAD Failure: Failed to load Application Insights SDK script (See stack for details)";