From 193c27b3f4831fdc60f026779c0dcbab8a24fb89 Mon Sep 17 00:00:00 2001 From: Thomas Hurst Date: Fri, 8 Mar 2024 19:51:33 +0000 Subject: [PATCH 1/3] Handle HTTP chunking across multi-byte boundaries When a response contains multi-byte UTF-8 characters that cross chunk boundaries, appending the two halves to the intermediate string results in two Unicode Replacement Characters being inserted instead of the two halves being joined. Set the response encoding to UTF-8 to ensure it buffers partial characters between chunks. Resolves #22 Co-authored-by: zyc9012 --- src/utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils.ts b/src/utils.ts index ef49a2a..a05fa05 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -63,6 +63,7 @@ export function execute( return new Promise((resolve, reject) => { let timer: number; const req = https.get(url, (resp) => { + resp.setEncoding("utf8"); let data = ""; // A chunk of data has been recieved. From 7610f9f4e9a683e9dbf439d433cc481f0b438a37 Mon Sep 17 00:00:00 2001 From: Thomas Hurst Date: Mon, 11 Mar 2024 21:29:59 +0000 Subject: [PATCH 2/3] deno fmt README.md --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 40145ec..6838391 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,9 @@ more. ### Node.js - Supports Node.js 7.10.1 and newer. -- Refer to [this example](https://github.com/serpapi/serpapi-javascript/tree/master/examples/node/js_node_7_up) for help. +- Refer to + [this example](https://github.com/serpapi/serpapi-javascript/tree/master/examples/node/js_node_7_up) + for help. ```bash npm install serpapi @@ -40,7 +42,9 @@ getJson({ - If you prefer using the `import` syntax and top-level `await`, you need to use at least Node.js 14.8.0. -- Refer to [this example](https://github.com/serpapi/serpapi-javascript/tree/master/examples/node/js_node_14_up) for help. +- Refer to + [this example](https://github.com/serpapi/serpapi-javascript/tree/master/examples/node/js_node_14_up) + for help. You will need to add `"type": "module"` to your `package.json`: @@ -66,7 +70,9 @@ console.log(response); - Import directly from deno.land. - Usage is otherwise the same as above. -- Refer to [this example](https://github.com/serpapi/serpapi-javascript/tree/master/examples/deno) for help. +- Refer to + [this example](https://github.com/serpapi/serpapi-javascript/tree/master/examples/deno) + for help. ```ts import { getJson } from "https://deno.land/x/serpapi/mod.ts"; From d9385fcb1879fcabcd4d4db36046c0807333ce6a Mon Sep 17 00:00:00 2001 From: Thomas Hurst Date: Mon, 11 Mar 2024 21:38:19 +0000 Subject: [PATCH 3/3] Fix CI for earlier node versions Node hardcodes its default TLS certificates, meaning older versions do not support the root certificate currently used by LetsEncrypt. Use --use-openssl-ca to enable the use of the system's OpenSSL certificates. Since node v7 doesn't support NODE_OPTIONS, conditionally modify the test script with sed. --- .github/workflows/build.yml | 13 +++++++++++-- smoke_tests/commonjs/package.json | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 239d75e..83b4b27 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,6 @@ name: Build -on: [push, pull_request] +on: [push] jobs: build: @@ -52,6 +52,15 @@ jobs: strategy: matrix: node-version: [7.x, 8.x, 9.x, 10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x, 18.x, 19.x] + include: + - command: test + - command: test:use-openssl-ca + node-version: 7.x + - command: test:use-openssl-ca + node-version: 8.x + - command: test:use-openssl-ca + node-version: 9.x + steps: - name: Checkout repo uses: actions/checkout@v3 @@ -76,7 +85,7 @@ jobs: run: | cd smoke_tests/commonjs npm i - npm test + npm run ${{ matrix.command }} smoke-tests-esm: name: "Smoke tests (ESM)" diff --git a/smoke_tests/commonjs/package.json b/smoke_tests/commonjs/package.json index f229cf1..d1971c6 100644 --- a/smoke_tests/commonjs/package.json +++ b/smoke_tests/commonjs/package.json @@ -4,6 +4,7 @@ "serpapi": "../../npm" }, "scripts": { - "test": "node commonjs.js" + "test": "node commonjs.js", + "test:use-openssl-ca": "node --use-openssl-ca commonjs.js" } }