From 87279392cf01608ba8ac4e80e6f52f40da39af94 Mon Sep 17 00:00:00 2001 From: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> Date: Fri, 25 Oct 2024 19:58:45 -0700 Subject: [PATCH 1/5] fix 9395 (#14815) --- src/bun.js/bindings/webcore/JSTextEncoder.cpp | 4 ++++ test/js/web/encoding/text-encoder.test.js | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/bun.js/bindings/webcore/JSTextEncoder.cpp b/src/bun.js/bindings/webcore/JSTextEncoder.cpp index d886ce16e342ec..e8264a73195d9a 100644 --- a/src/bun.js/bindings/webcore/JSTextEncoder.cpp +++ b/src/bun.js/bindings/webcore/JSTextEncoder.cpp @@ -378,6 +378,10 @@ static inline JSC::EncodedJSValue jsTextEncoderPrototypeFunction_encodeBody(JSC: UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); EnsureStillAliveScope argument0 = callFrame->argument(0); + if (argument0.value().isUndefined()) { + auto res = JSC::JSUint8Array::create(lexicalGlobalObject, lexicalGlobalObject->m_typedArrayUint8.get(lexicalGlobalObject), 0); + RELEASE_AND_RETURN(throwScope, JSValue::encode(res)); + } JSC::JSString* input = argument0.value().toStringOrNull(lexicalGlobalObject); JSC::EncodedJSValue res; String str; diff --git a/test/js/web/encoding/text-encoder.test.js b/test/js/web/encoding/text-encoder.test.js index 0eb1a001fe3fb1..af7aff0efea1a1 100644 --- a/test/js/web/encoding/text-encoder.test.js +++ b/test/js/web/encoding/text-encoder.test.js @@ -23,6 +23,12 @@ it("not enough space for replacement character", () => { }); describe("TextEncoder", () => { + it("should handle undefined", () => { + const encoder = new TextEncoder(); + expect(encoder.encode(undefined).length).toBe(0); + expect(encoder.encode(null).length).toBe(4); + expect(encoder.encode("").length).toBe(0); + }); it("should encode latin1 text with non-ascii latin1 characters", () => { var text = "H©ell©o Wor©ld!"; From 4f5660a6f78f1d7ff80bce319c2f9232830dac1c Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Fri, 25 Oct 2024 23:40:27 -0700 Subject: [PATCH 2/5] Add sentry id to crash report comment --- .github/workflows/labeled.yml | 56 +++++++++++++++++++++++++- scripts/associate-issue-with-sentry.ts | 49 ++++++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 scripts/associate-issue-with-sentry.ts diff --git a/.github/workflows/labeled.yml b/.github/workflows/labeled.yml index 7dacfa985f10d8..a5a55b2e9f71bd 100644 --- a/.github/workflows/labeled.yml +++ b/.github/workflows/labeled.yml @@ -83,6 +83,26 @@ jobs: echo "latest=$(cat LATEST)" >> $GITHUB_OUTPUT rm -rf is-outdated.txt outdated.txt latest.txt + - name: Generate comment text with Sentry Link + if: github.event.label.name == 'crash' + # ignore if fail + continue-on-error: true + id: generate-comment-text + env: + GITHUB_ISSUE_BODY: ${{ github.event.issue.body }} + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + shell: bash + run: | + bun scripts/associate-issue-with-sentry.ts + + if [[ -f "sentry-link.txt" ]]; then + echo "sentry-link=$(cat sentry-link.txt)" >> $GITHUB_OUTPUT + fi + + if [[ -f "sentry-id.txt" ]]; then + echo "sentry-id=$(cat sentry-id.txt)" >> $GITHUB_OUTPUT + fi + - name: Add labels uses: actions-cool/issues-helper@v3 if: github.event.label.name == 'crash' @@ -92,7 +112,7 @@ jobs: issue-number: ${{ github.event.issue.number }} labels: ${{ steps.add-labels.outputs.labels }} - name: Comment outdated - if: steps.add-labels.outputs.is-outdated == 'true' && github.event.label.name == 'crash' + if: steps.add-labels.outputs.is-outdated == 'true' && github.event.label.name == 'crash' && steps.generate-comment-text.outputs.sentry-link == '' uses: actions-cool/issues-helper@v3 with: actions: "create-comment" @@ -106,6 +126,40 @@ jobs: ```sh bun upgrade ``` + - name: Comment with Sentry Link and outdated version + if: steps.generate-comment-text.outputs.sentry-link != '' && github.event.label.name == 'crash' && steps.add-labels.outputs.is-outdated == 'true' + uses: actions-cool/issues-helper@v3 + with: + actions: "create-comment" + token: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.issue.number }} + body: | + @${{ github.event.issue.user.login }}, thank you for reporting this crash. The latest version of Bun is v${{ steps.add-labels.outputs.latest }}, but this crash was reported on Bun v${{ steps.add-labels.outputs.oudated }}. + + Are you able to reproduce this crash on the latest version of Bun? + + ```sh + bun upgrade + ``` + + For Bun's internal tracking, this issue is [${{ steps.generate-comment-text.outputs.sentry-id }}](${{ steps.generate-comment-text.outputs.sentry-link }}). + + + + - name: Comment with Sentry Link + if: steps.generate-comment-text.outputs.sentry-link != '' && github.event.label.name == 'crash' && steps.add-labels.outputs.is-outdated != 'true' + uses: actions-cool/issues-helper@v3 + with: + actions: "create-comment" + token: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.issue.number }} + body: | + Thank you for reporting this crash. + + For Bun's internal tracking, this issue is [${{ steps.generate-comment-text.outputs.sentry-id }}](${{ steps.generate-comment-text.outputs.sentry-link }}). + + + - name: Comment needs repro if: github.event.label.name == 'needs repro' uses: actions-cool/issues-helper@v3 diff --git a/scripts/associate-issue-with-sentry.ts b/scripts/associate-issue-with-sentry.ts new file mode 100644 index 00000000000000..66a79f1746ffe5 --- /dev/null +++ b/scripts/associate-issue-with-sentry.ts @@ -0,0 +1,49 @@ +const body = process.env.GITHUB_ISSUE_BODY; +const SENTRY_AUTH_TOKEN = process.env.SENTRY_AUTH_TOKEN; + +if (!body || !SENTRY_AUTH_TOKEN) { + throw new Error("Missing environment variables"); +} + +const id = body.indexOf("", id + 1); +if (!(id > -1 && endIdLine > -1)) { + throw new Error("Missing sentry_id"); +} +const sentryId = body.slice(id + "