nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: mcollina/autocannon
Pull request #414 (2021-12-16 00:35:20)

fix: Fix JSON array body on CLI
Fixes: https://github.com/mcollina/autocannon/issues/413

silverwind: By the way: I did not explore the option to replace `subarg` with `minimist` (which I think is the proper solution), because I saw `subarg`'s context feature being in active use, so the replacement would be a breaking one (thought it's one I'd be willing to take).

Patch:
diff --git a/lib/httpRequestBuilder.js b/lib/httpRequestBuilder.js
index 80591f7..30e2a0d 100644
--- a/lib/httpRequestBuilder.js
+++ b/lib/httpRequestBuilder.js
@@ -72,6 +72,11 @@ function requestBuilder (defaults) {
       bodyBuf = Buffer.from(body)
     } else if (Buffer.isBuffer(body)) {
       bodyBuf = body
+    } else if (body && Array.isArray(body._)) {
+      // when the request body passed on the CLI includes brackets like for
+      // a JSON array, the subarg parser will oddly provide the contents as
+      // `body._`. Work around this specific issue.
+      bodyBuf = Buffer.from(`[${body._}]`)
     } else if (body) {
       throw new Error('body must be either a string or a buffer')
     }


Test patch:
diff --git a/test/httpClient.test.js b/test/httpClient.test.js
index e1d663f..a63e1e7 100644
--- a/test/httpClient.test.js
+++ b/test/httpClient.test.js
@@ -424,6 +424,34 @@ test('client supports sending a body which is a string', (t) => {
   })
 })
 
+test('client supports sending a body passed on the CLI as JSON array', (t) => {
+  t.plan(3)
+
+  const body = [{ a: [{ b: 1 }] }]
+  const jsonBody = JSON.stringify(body)
+
+  // this odd format is parsed by the subarg parser when body is a JSON array
+  const mangledBody = { _: [JSON.stringify(body[0])] }
+
+  const opts = server.address()
+  opts.method = 'POST'
+  opts.body = mangledBody
+
+  const client = new Client(opts)
+
+  server.once('request', (req, res) => {
+    req.pipe(bl((err, body) => {
+      t.error(err)
+      t.same(body.toString(), jsonBody, 'body matches')
+    }))
+  })
+
+  client.on('response', (statusCode, length) => {
+    t.equal(statusCode, 200, 'status code matches')
+    client.destroy()
+  })
+})
+
 test('client supports changing the body', (t) => {
   t.plan(2)
Repository: mcollina/autocannon
Pull request #463 (2022-09-20 14:50:17)

Accept host header case-insensitively
This makes CLI `-H 'Host: foo'` work where previously it did not identify the header correctly because it was case-sensitive.

silverwind: Will try to fix the test, I didn't test locally because I see around 30 test failures even on a clean branch.
silverwind: Should be good to go now. Previous failures were odd timing flakes on the CI. I also disabled `fail-fast` behaviour because I think it's much more useful to have all jobs to always run to completion.

Patch:
diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml
index 6b28ed1..c4b709e 100644
--- a/.github/workflows/nodejs.yml
+++ b/.github/workflows/nodejs.yml
@@ -13,6 +13,7 @@ jobs:
     permissions:
       contents: read
     strategy:
+      fail-fast: false
       matrix:
         os: [ubuntu-latest, windows-latest, macos-latest]
         node-version: [14, 16, 18]
diff --git a/lib/httpRequestBuilder.js b/lib/httpRequestBuilder.js
index 30e2a0d..1319902 100644
--- a/lib/httpRequestBuilder.js
+++ b/lib/httpRequestBuilder.js
@@ -1,6 +1,7 @@
 'use strict'
 
 const methods = require('./httpMethods')
+const { getPropertyCaseInsensitive } = require('./util')
 
 // this is a build request factory, that curries the build request function
 // and sets the default for it
@@ -44,7 +45,8 @@ function requestBuilder (defaults) {
     const headers = reqData.headers
     const body = reqData.body
 
-    let host = reqData.headers.host || reqData.host
+    let host = getPropertyCaseInsensitive(reqData.headers, 'host') || reqData.host
+
     if (!host) {
       const hostname = reqData.hostname
       const port = reqData.port
diff --git a/lib/util.js b/lib/util.js
index 2cd14c8..a0c3e4b 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -3,4 +3,10 @@
 const semver = require('semver')
 const hasWorkerSupport = semver.gte(process.versions.node, '11.7.0')
 
-module.exports = { hasWorkerSupport }
+function getPropertyCaseInsensitive (obj, key) {
+  for (const objKey of Object.keys(obj)) {
+    if (objKey.toLowerCase() === key.toLowerCase()) return obj[objKey]
+  }
+}
+
+module.exports = { hasWorkerSupport, getPropertyCaseInsensitive }


Test patch:
diff --git a/test/httpClient.test.js b/test/httpClient.test.js
index a63e1e7..fc29473 100644
--- a/test/httpClient.test.js
+++ b/test/httpClient.test.js
@@ -334,6 +334,25 @@ test('client supports host custom header', (t) => {
   })
 })
 
+test('client supports host custom header with mixed case', (t) => {
+  t.plan(2)
+
+  const opts = server.address()
+  opts.headers = {
+    Host: 'www.autocannon.com'
+  }
+  const client = new Client(opts)
+
+  server.once('request', (req, res) => {
+    t.equal(req.headers.host, 'www.autocannon.com', 'host header matches')
+  })
+
+  client.on('response', (statusCode, length) => {
+    t.equal(statusCode, 200, 'status code matches')
+    client.destroy()
+  })
+})
+
 test('client supports response trailers', (t) => {
   t.plan(3)
Repository: hhursev/recipe-scrapers
Pull request #405 (2021-07-11 12:39:10)

Fixup: omit nutrient fields that have no value present
I don't think it makes sense to include nutrient field names where there is no value present.  In addition, `normalize_string` does not currently work correctly for inputs of type `NoneType`.  That method could do with some attention and perhaps be refactored out eventually.


Patch:
diff --git a/recipe_scrapers/_schemaorg.py b/recipe_scrapers/_schemaorg.py
index 076967a2..10827723 100644
--- a/recipe_scrapers/_schemaorg.py
+++ b/recipe_scrapers/_schemaorg.py
@@ -117,7 +117,7 @@ class SchemaOrg:
         return {
             normalize_string(nutrient): normalize_string(value)
             for nutrient, value in nutrients.items()
-            if nutrient != "@type"
+            if nutrient != "@type" and value is not None
         }
 
     def _extract_howto_instructions_text(self, schema_item):


Test patch:
diff --git a/tests/test_data/schemaorg.testhtml b/tests/test_data/schemaorg.testhtml
index 22400bca..cb24424d 100644
--- a/tests/test_data/schemaorg.testhtml
+++ b/tests/test_data/schemaorg.testhtml
@@ -23,7 +23,8 @@
           "nutrition": {
             "@type": "NutritionInformation",
             "calories": "240 calories",
-            "fatContent": "9 grams fat"
+            "fatContent": "9 grams fat",
+            "servingSize": null
           },
           "prepTime": "PT15M",
           "recipeInstructions": "Preheat the oven to 350 degrees. Mix in the ingredients in a bowl. Add the flour last. Pour the mixture into a loaf pan and bake for one hour.",
diff --git a/tests/test_schemaorg.py b/tests/test_schemaorg.py
index be0ce0fc..1856e06a 100644
--- a/tests/test_schemaorg.py
+++ b/tests/test_schemaorg.py
@@ -25,6 +25,13 @@ class TestSchemaOrg(unittest.TestCase):
         del self.schema.data["totalTime"]
         self.assertEqual(self.schema.total_time(), 0)
 
+    def test_nutrient_retrieval(self):
+        expected_nutrients = {
+            "calories": "240 calories",
+            "fatContent": "9 grams fat",
+        }
+        self.assertEqual(self.schema.nutrients(), expected_nutrients)
+
     def test_graph_schema_without_context(self):
         with open(
             "tests/test_data/schemaorg_graph.testhtml", encoding="utf-8"
Repository: hhursev/recipe-scrapers
Pull request #412 (2021-07-16 05:48:19)

Serious Eats author
Fixes author Not Implemented for Serious Eats.

- [x] pre-commit passed
- [x] `test_seriouseats.py` updated
- [x] passing build tests


Patch:
diff --git a/recipe_scrapers/seriouseats.py b/recipe_scrapers/seriouseats.py
index e6b27029..04aee05a 100644
--- a/recipe_scrapers/seriouseats.py
+++ b/recipe_scrapers/seriouseats.py
@@ -7,6 +7,10 @@ class SeriousEats(AbstractScraper):
     def host(cls):
         return "seriouseats.com"
 
+    def author(self):
+        author = self.soup.find("meta", {"name": "sailthru.author"})
+        return author["content"] if author else None
+
     def title(self):
         return self.soup.find("h1").get_text()
 


Test patch:
diff --git a/tests/test_seriouseats.py b/tests/test_seriouseats.py
index 6634c5a3..8b6a7057 100644
--- a/tests/test_seriouseats.py
+++ b/tests/test_seriouseats.py
@@ -15,6 +15,9 @@ class TestSeriousEats(ScraperTest):
             self.harvester_class.canonical_url(),
         )
 
+    def test_author(self):
+        self.assertEqual(self.harvester_class.author(), "Daniel Gritzer")
+
     def test_title(self):
         self.assertEqual(
             self.harvester_class.title(), "Homemade Preserved Horseradish Recipe"