Skip to content

Commit 6385933

Browse files
committed
Preserve invalid environment overrides as unspecified
1 parent af5bea4 commit 6385933

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

packages/core/src/EventBuilder.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import { Event, EventType, KnownEventDataKeys } from "./models/Event.js";
33
import { ManualStackingInfo } from "./models/data/ManualStackingInfo.js";
44
import { UserInfo } from "./models/data/UserInfo.js";
55
import { EventContext } from "./models/EventContext.js";
6-
import { isEmpty, normalizeEnvironment, stringify } from "./Utils.js";
6+
import { isEmpty, stringify } from "./Utils.js";
77
import { EventPluginContext } from "./plugins/EventPluginContext.js";
88

99
export class EventBuilder {
1010
public setEnvironment(value: string | null | undefined): EventBuilder {
11-
const environment = normalizeEnvironment(value);
12-
if (environment) {
13-
this.target.environment = environment;
11+
if (value != null) {
12+
this.target.environment = value;
1413
} else {
1514
delete this.target.environment;
1615
}

packages/core/src/Utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ export function normalizeEnvironment(value: string | null | undefined): string |
563563
if (typeof value !== "string") {
564564
return undefined;
565565
}
566-
const name = value.trim();
566+
const name = value.trim().toLowerCase();
567567
// eslint-disable-next-line no-control-regex -- Deployment names cannot contain control characters.
568-
return name && name.length <= 64 && !/[\u0000-\u001f\u007f-\u009f]/u.test(name) ? name.toLowerCase() : undefined;
568+
return name && name.length <= 64 && !/[\u0000-\u001f\u007f-\u009f]/u.test(name) ? name : undefined;
569569
}

packages/core/test/plugins/default/ConfigurationDefaultsPlugin.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ describe("ConfigurationDefaultsPlugin", () => {
2424
expect(JSON.parse(JSON.stringify(builder.target)).environment).toBe("staging");
2525
});
2626

27+
test.each(["", " ", "x".repeat(65), "prod\ninvalid", "İ".repeat(64)])("should keep invalid override %j unspecified", async (environment) => {
28+
const client = new ExceptionlessClient();
29+
client.config.environment = "production";
30+
const builder = client.createLog("test", "message").setEnvironment(environment);
31+
await new ConfigurationDefaultsPlugin().run(new EventPluginContext(client, builder.target, new EventContext()));
32+
expect(builder.target.environment).toBeUndefined();
33+
});
34+
2735
describe("should add default", () => {
2836
const userDataKey: string = "user";
2937
const user = {

0 commit comments

Comments
 (0)