File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
main/java/com/microsoft/applicationinsights/telemetry
test/java/com/microsoft/applicationinsights/telemetry Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 2121
2222package com .microsoft .applicationinsights .telemetry ;
2323
24- import com .microsoft .applicationinsights .agent .internal .common .StringUtils ;
2524import com .microsoft .applicationinsights .internal .schemav2 .Data ;
2625import com .microsoft .applicationinsights .internal .schemav2 .Domain ;
2726import com .microsoft .applicationinsights .internal .schemav2 .Envelope ;
3433import java .util .concurrent .ConcurrentHashMap ;
3534import java .util .concurrent .ConcurrentMap ;
3635
36+ import org .apache .commons .lang3 .StringUtils ;
37+
3738/**
3839 * Superclass for all telemetry data classes.
3940 */
@@ -192,7 +193,7 @@ protected String getBaseTypeName() {
192193 }
193194
194195 private String normalizeInstrumentationKey (String instrumentationKey ){
195- if (StringUtils .isNullOrEmpty (instrumentationKey )){
196+ if (StringUtils .isEmpty (instrumentationKey ) || StringUtils . containsOnly ( instrumentationKey , ".- " )){
196197 return "" ;
197198 }
198199 else {
Original file line number Diff line number Diff line change 3030
3131import java .io .IOException ;
3232import java .io .StringWriter ;
33- import java .lang .reflect .*;
3433import java .util .Date ;
3534import java .util .concurrent .ConcurrentHashMap ;
3635import java .util .concurrent .ConcurrentMap ;
@@ -143,6 +142,21 @@ public void testTelemetryNameWithIkey() throws IOException{
143142 assertTrue (index != -1 );
144143 }
145144
145+ @ Test
146+ public void testTelemetryNameWithIkey_SpecialChar () throws IOException {
147+ StubTelemetry telemetry = new StubTelemetry ("Test Base Telemetry" );
148+ telemetry .getContext ().setInstrumentationKey ("--. .--" );
149+ telemetry .setTimestamp (new Date ());
150+
151+ StringWriter writer = new StringWriter ();
152+ JsonTelemetryDataSerializer jsonWriter = new JsonTelemetryDataSerializer (writer );
153+ telemetry .serialize (jsonWriter );
154+ jsonWriter .close ();
155+ String asJson = writer .toString ();
156+
157+ int index = asJson .indexOf ("\" name\" :\" Microsoft.ApplicationInsights.Stub\" " );
158+ assertTrue (index != -1 );
159+ }
146160
147161 @ Test
148162 public void testTelemetryNameWithIkey_Empty () throws IOException {
You can’t perform that action at this time.
0 commit comments