Skip to content

Commit bcd5a3a

Browse files
Cover newline-tab wrapped websocket protocol validation
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent 3e7fe1f commit bcd5a3a

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

docs/tasks/streams.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ Examples:
689689
-`\u205F///\u205F` (empty after trimming wrapper whitespace)
690690
-`\u3000///\u3000` (empty after trimming wrapper whitespace)
691691
-`\n\thttps://api.trigger.dev/base/?query=1\t\n` (query is still rejected after trimming wrappers)
692+
-`\n\tws://api.trigger.dev\t\n` / `\n\twss://api.trigger.dev\t\n` (trimmed wrappers still reject websocket protocols)
692693
-`https://api.trigger.dev/\ninternal`
693694
-`https://api.trigger.dev/in valid`
694695
-`https://api.trigger.dev/\tinternal`

packages/ai/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ Examples:
196196
-`\u205F///\u205F` (empty after trimming wrapper whitespace)
197197
-`\u3000///\u3000` (empty after trimming wrapper whitespace)
198198
-`\n\thttps://api.trigger.dev/base/?query=1\t\n` (query is still rejected after trimming wrappers)
199+
-`\n\tws://api.trigger.dev\t\n` / `\n\twss://api.trigger.dev\t\n` (trimmed wrappers still reject websocket protocols)
199200
-`https://api.trigger.dev/\ninternal` (internal whitespace characters)
200201
-`https://api.trigger.dev/in valid` (internal space characters)
201202
-`https://api.trigger.dev/\tinternal` (internal tab characters)

packages/ai/src/chatTransport.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,17 @@ describe("TriggerChatTransport", function () {
10611061
}).toThrowError("baseURL must use http or https protocol");
10621062
});
10631063

1064+
it("throws when newline-and-tab wrapped baseURL protocol is ws", function () {
1065+
expect(function () {
1066+
new TriggerChatTransport({
1067+
task: "chat-task",
1068+
accessToken: "pk_trigger",
1069+
baseURL: "\n\tws://example.com\t\n",
1070+
stream: "chat-stream",
1071+
});
1072+
}).toThrowError("baseURL must use http or https protocol");
1073+
});
1074+
10641075
it("throws when baseURL protocol is wss", function () {
10651076
expect(function () {
10661077
new TriggerChatTransport({
@@ -1083,6 +1094,17 @@ describe("TriggerChatTransport", function () {
10831094
}).toThrowError("baseURL must use http or https protocol");
10841095
});
10851096

1097+
it("throws when newline-and-tab wrapped baseURL protocol is wss", function () {
1098+
expect(function () {
1099+
new TriggerChatTransport({
1100+
task: "chat-task",
1101+
accessToken: "pk_trigger",
1102+
baseURL: "\n\twss://example.com\t\n",
1103+
stream: "chat-stream",
1104+
});
1105+
}).toThrowError("baseURL must use http or https protocol");
1106+
});
1107+
10861108
it("throws when baseURL includes query parameters", function () {
10871109
expect(function () {
10881110
new TriggerChatTransport({
@@ -4053,6 +4075,17 @@ describe("TriggerChatTransport", function () {
40534075
}).toThrowError("baseURL must use http or https protocol");
40544076
});
40554077

4078+
it("throws from factory when newline-and-tab wrapped baseURL protocol is ws", function () {
4079+
expect(function () {
4080+
createTriggerChatTransport({
4081+
task: "chat-task",
4082+
accessToken: "pk_trigger",
4083+
baseURL: "\n\tws://example.com\t\n",
4084+
stream: "chat-stream",
4085+
});
4086+
}).toThrowError("baseURL must use http or https protocol");
4087+
});
4088+
40564089
it("throws from factory when baseURL protocol is wss", function () {
40574090
expect(function () {
40584091
createTriggerChatTransport({
@@ -4075,6 +4108,17 @@ describe("TriggerChatTransport", function () {
40754108
}).toThrowError("baseURL must use http or https protocol");
40764109
});
40774110

4111+
it("throws from factory when newline-and-tab wrapped baseURL protocol is wss", function () {
4112+
expect(function () {
4113+
createTriggerChatTransport({
4114+
task: "chat-task",
4115+
accessToken: "pk_trigger",
4116+
baseURL: "\n\twss://example.com\t\n",
4117+
stream: "chat-stream",
4118+
});
4119+
}).toThrowError("baseURL must use http or https protocol");
4120+
});
4121+
40784122
it("throws from factory when baseURL includes query parameters", function () {
40794123
expect(function () {
40804124
createTriggerChatTransport({

0 commit comments

Comments
 (0)