nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: eemeli/yaml
Pull request #498 (2023-10-13 10:19:45)

Fix malformed uri
While [Fuzzing](https://en.wikipedia.org/wiki/Fuzzing) locally using [jazzer.js](https://github.com/CodeIntelligenceTesting/jazzer.js) `YAML.parse()` threw uncaught exception at
https://github.com/eemeli/yaml/blob/a4d8569c2139eee8a0324b6b861283f7b3b508f8/src/doc/directives.ts#L149 this pr attempts to fix that.
```
URIError: URI malformed
    at decodeURIComponent (<anonymous>)
    at Directives.tagName (/home/maxx/dev/security/oss-fuzz-projects/eemeli-yaml/dist/doc/directives.js:126:29)
```


Patch:
diff --git a/src/doc/directives.ts b/src/doc/directives.ts
index 4978c07..add18fc 100644
--- a/src/doc/directives.ts
+++ b/src/doc/directives.ts
@@ -146,7 +146,14 @@ export class Directives {
     const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/) as string[]
     if (!suffix) onError(`The ${source} tag has no suffix`)
     const prefix = this.tags[handle]
-    if (prefix) return prefix + decodeURIComponent(suffix)
+    if (prefix) {
+      try {
+        return prefix + decodeURIComponent(suffix)
+      } catch (error) {
+        onError(String(error))
+        return null
+      }
+    }
     if (handle === '!') return source // local tag
 
     onError(`Could not resolve tag: ${source}`)


Test patch:
diff --git a/tests/doc/types.ts b/tests/doc/types.ts
index c03668b..28f2180 100644
--- a/tests/doc/types.ts
+++ b/tests/doc/types.ts
@@ -106,6 +106,12 @@ describe('tags', () => {
         expect(doc.errors[0].code).toBe('MISSING_CHAR')
       })
     }
+
+    test('malformed URI (eemeli/yaml#498)', () => {
+      const doc = parseDocument('!!%ee 0')
+      expect(doc.errors).toHaveLength(1)
+      expect(doc.errors[0].message).toMatch('URIError')
+    })
   })
 
   test('eemeli/yaml#97', () => {
Repository: eemeli/yaml
Pull request #522 (2024-02-12 19:16:34)

fix: use the `lineWidth` option for line breaking in flow collections
This should address issues #288 and #507.

no92: I also amended the commit to include two testcases, with one that wraps and another test that does not.

Patch:
diff --git a/src/stringify/stringifyCollection.ts b/src/stringify/stringifyCollection.ts
index a572718..0892549 100644
--- a/src/stringify/stringifyCollection.ts
+++ b/src/stringify/stringifyCollection.ts
@@ -148,7 +148,7 @@ function stringifyFlowCollection(
   } else {
     if (!reqNewline) {
       const len = lines.reduce((sum, line) => sum + line.length + 2, 2)
-      reqNewline = len > Collection.maxFlowStringSingleLineLength
+      reqNewline = ctx.options.lineWidth > 0 && len > ctx.options.lineWidth
     }
     if (reqNewline) {
       str = start


Test patch:
diff --git a/tests/doc/stringify.ts b/tests/doc/stringify.ts
index a094203..c7b7bf2 100644
--- a/tests/doc/stringify.ts
+++ b/tests/doc/stringify.ts
@@ -616,7 +616,7 @@ describe('scalar styles', () => {
   y,
   n
 ]\n`
-    expect(String(doc)).toBe(str)
+    expect(doc.toString({ lineWidth: 1 })).toBe(str)
     expect(YAML.parse(str)).toEqual([
       true,
       false,
@@ -868,6 +868,36 @@ describe('indentSeq: false', () => {
   })
 })
 
+describe('lineWidth', () => {
+  const doc = YAML.parseDocument(
+    "[ 'Sed', 'ut', 'perspiciatis', 'unde', 'omnis', 'iste', 'natus', 'error', 'sit', 'voluptatem', 'accusantium', 'doloremque', 'laudantium,', 'totam' ]"
+  )
+
+  test('limit to 80 with overlong flow collection', () => {
+    expect(doc.toString({lineWidth: 80})).toBe(`[
+  'Sed',
+  'ut',
+  'perspiciatis',
+  'unde',
+  'omnis',
+  'iste',
+  'natus',
+  'error',
+  'sit',
+  'voluptatem',
+  'accusantium',
+  'doloremque',
+  'laudantium,',
+  'totam'
+]
+`)
+  })
+
+  test('limit > flow collection length', () => {
+    expect(doc.toString({lineWidth: 162})).toBe("[ 'Sed', 'ut', 'perspiciatis', 'unde', 'omnis', 'iste', 'natus', 'error', 'sit', 'voluptatem', 'accusantium', 'doloremque', 'laudantium,', 'totam' ]\n")
+  })
+})
+
 describe('collectionStyle', () => {
   test('collectionStyle: undefined', () => {
     const doc = new YAML.Document<YAML.YAMLMap, false>({ foo: ['bar'] })
Repository: eemeli/yaml
Pull request #530 (2024-03-07 14:06:19)

Fix `false` capitalization
With `yaml-1.1` the lib incorrectly parses badly capitalized literals like `FALse` and `OfF` as a `false` value. This PR fixes it.


Patch:
diff --git a/src/schema/yaml-1.1/bool.ts b/src/schema/yaml-1.1/bool.ts
index a6a4f69..10d68d4 100644
--- a/src/schema/yaml-1.1/bool.ts
+++ b/src/schema/yaml-1.1/bool.ts
@@ -21,7 +21,7 @@ export const falseTag: ScalarTag & { test: RegExp } = {
   identify: value => value === false,
   default: true,
   tag: 'tag:yaml.org,2002:bool',
-  test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,
+  test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,
   resolve: () => new Scalar(false),
   stringify: boolStringify
 }


Test patch:
diff --git a/tests/doc/stringify.ts b/tests/doc/stringify.ts
index 5e3f7b6..0ff20d5 100644
--- a/tests/doc/stringify.ts
+++ b/tests/doc/stringify.ts
@@ -633,7 +633,7 @@ describe('scalar styles', () => {
 
   test('bool Scalar styles on YAML1.1', () => {
     const doc = YAML.parseDocument(
-      '[ n, N, NO, no, No, False, false, FALSE, Off, off, OFF, y, Y, Yes, yes, YES, true, True, TRUE, ON, on, On ]',
+      '[ n, N, NO, no, No, False, false, FALSE, FALse, Off, off, OFF, OfF, y, Y, Yes, yes, YES, true, True, TRUE, ON, on, On ]',
       { schema: 'yaml-1.1' }
     )
     const str = `[
@@ -645,9 +645,11 @@ describe('scalar styles', () => {
   False,
   false,
   FALSE,
+  FALse,
   Off,
   off,
   OFF,
+  OfF,
   y,
   Y,
   Yes,
@@ -670,9 +672,11 @@ describe('scalar styles', () => {
       false,
       false,
       false,
+      'FALse',
       false,
       false,
       false,
+      'OfF',
       true,
       true,
       true,
Repository: eemeli/yaml
Pull request #587 (2024-11-12 08:08:18)

Update schema.ts
CodeQL is complaining about missing js regex anchors.

`Misleading operator precedence. The subexpression '^true' is anchored at the beginning, but the other parts of this regular expression are not
Misleading operator precedence. The subexpression 'false$' is anchored at the end, but the other parts of this regular expression are not`

https://codeql.github.com/codeql-query-help/javascript/js-regex-missing-regexp-anchor/


eemeli: Huh, that is indeed a bug. Should probably add a test or two for this as well, probably around [here](https://github.com/eemeli/yaml/blob/2e85b914b918b13e3985c58b1ce735d2c3f5a813/tests/doc/types.ts#L268). Would you be up to doing so?
vra5107: @eemeli I have added a test. Did run it locally and it does pass. It does return an error for something like `ffalse` but reports no errors for something like `Truea`. If you can kindly merge and release a new version, I will pull the latest version. Security is a mania these days.



Patch:
diff --git a/src/schema/json/schema.ts b/src/schema/json/schema.ts
index a4b5725..d842401 100644
--- a/src/schema/json/schema.ts
+++ b/src/schema/json/schema.ts
@@ -30,7 +30,7 @@ const jsonScalars: ScalarTag[] = [
     identify: value => typeof value === 'boolean',
     default: true,
     tag: 'tag:yaml.org,2002:bool',
-    test: /^true|false$/,
+    test: /^true$|^false$/,
     resolve: str => str === 'true',
     stringify: stringifyJSON
   },


Test patch:
diff --git a/tests/doc/types.ts b/tests/doc/types.ts
index bd3c066..c2627d5 100644
--- a/tests/doc/types.ts
+++ b/tests/doc/types.ts
@@ -285,6 +285,26 @@ describe('json schema', () => {
     )
   })
 
+  test('!!bool: js-regex-missing-regexp-anchor', () => {
+    const src = `"canonical": truea
+"answer": ffalse
+"logical": Truea
+"option": TruEp`
+
+    const doc = parseDocument(src, { schema: 'json' })
+    expect(doc.toJS()).toMatchObject({
+      canonical: 'truea',
+      answer: 'ffalse',
+      logical: 'Truea',
+      option: 'TruEp'
+    })
+    expect(doc.errors).toHaveLength(4)
+    doc.errors = []
+    expect(String(doc)).toBe(
+      '"canonical": "truea"\n"answer": "ffalse"\n"logical": "Truea"\n"option": "TruEp"\n'
+    )
+  })
+
   test('!!float', () => {
     const src = `"canonical": 6.8523015e+5
 "fixed": 685230.15