nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: yargs/yargs-parser
Pull request #9 (2016-02-21 17:24:04)

Copy args before parsing
When a flag is encountered with nargs set, and = is used, the input args array is modified. This breaks recursive command parsing in yargs itself.

Copy the args before parsing and add a test which shows the problem.

Fixes https://github.com/yargs/yargs/issues/396


Patch:
diff --git a/index.js b/index.js
index 17e69fd..a80c04c 100644
--- a/index.js
+++ b/index.js
@@ -626,7 +626,7 @@ function increment (orig) {
 }
 
 function Parser (args, opts) {
-  var result = parse(args, opts)
+  var result = parse(args.slice(), opts)
 
   return result.argv
 }
@@ -634,7 +634,7 @@ function Parser (args, opts) {
 // parse arguments and return detailed
 // meta information, aliases, etc.
 Parser.detailed = function (args, opts) {
-  return parse(args, opts)
+  return parse(args.slice(), opts)
 }
 
 module.exports = Parser


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index 8364d9b..d16e90e 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -1270,6 +1270,26 @@ describe('yargs-parser', function () {
       result._[1].should.equal('cat')
     })
 
+    it('should not modify the input args if an = was used', function () {
+      var expected = ['-f=apple', 'bar', 'blerg', '--bar=monkey', 'washing', 'cat']
+      var args = expected.slice()
+      parser(args, {
+        narg: {
+          f: 2,
+          bar: 2
+        }
+      })
+      args.should.deep.equal(expected)
+
+      parser.detailed(args, {
+        narg: {
+          f: 2,
+          bar: 2
+        }
+      })
+      args.should.deep.equal(expected)
+    })
+
     it('allows multiple nargs to be set at the same time', function () {
       var result = parser([ '--foo', 'apple', 'bar', '--bar', 'banana', '-f' ], {
         narg: {
Repository: yargs/yargs-parser
Pull request #10 (2016-03-16 01:55:41)

Join 'keys' in hasKey() when 'dot-notation' is turned off
I added a check for `configuration['dot-notation']` in `hasKey`, just like `setKey` already has. This way, if dot-notation is turned off, the keys will be joined. Therefore `hasKey` will be able to correctly tell if the key is in `obj`, without trying to check nested objects.

Without this fix, some errors occur when calling `applyDefaultsAndAliases` (which is the only method that calls `hasKey`) while dot-notation is disabled. For example:

- Values from the cli would fail to override defaults, if the defaults have dots.
- Values from the cli also fail to override aliases, if the aliases have dots.


Patch:
diff --git a/index.js b/index.js
index 1669a71..0442922 100644
--- a/index.js
+++ b/index.js
@@ -450,6 +450,9 @@ function parse (args, opts) {
 
   function hasKey (obj, keys) {
     var o = obj
+
+    if (!configuration['dot-notation']) keys = [keys.join('.')]
+
     keys.slice(0, -1).forEach(function (key) {
       o = (o[key] || {})
     })


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index 9fbd079..fdc75fa 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -1531,6 +1531,35 @@ describe('yargs-parser', function () {
         })
         expect(parsed['foo.bar']).to.equal('banana')
       })
+
+      it('should use value from cli, if cli overrides dot notation default', function () {
+        var parsed = parser(['--foo.bar', 'abc'], {
+          default: {
+            'foo.bar': 'default'
+          },
+          configuration: {
+            'dot-notation': false
+          }
+        })
+
+        expect(parsed['foo.bar']).to.equal('abc')
+      })
+
+      it('should also override dot notation alias', function () {
+        var parsed = parser(['--foo.bar', 'abc'], {
+          alias: {
+            'foo.bar': ['alias.bar']
+          },
+          default: {
+            'foo.bar': 'default'
+          },
+          configuration: {
+            'dot-notation': false
+          }
+        })
+
+        expect(parsed['alias.bar']).to.equal('abc')
+      })
     })
 
     describe('parse numbers', function () {
Repository: yargs/yargs-parser
Pull request #13 (2016-03-28 02:01:11)

Fix args.splice() when handling the case '--foo=xxx' with nargs or arrays
When handling the `--f=a b c` case, if the key of `--f=a` is in 'nargs' or 'arrays', then the value 'a' is added as the next item in 'args'. 

There's an issue with the call used for that: `args.splice(i + 1, m[1], m[2])`, where `m[1]` is the key and `m[2]` is the value. There should be a zero in place of `m[1]`, because the signature of splice is `array.splice(start, deleteCount[, item1[, item2[, ...]]])`, and we don't actually try to delete anything from 'args'.

An edge case error occurs if the key is actually a number. If so, that number of items will be deleted from args. (For example: Calling with `--1=a b` will result in `1 = ["a", null]`).

Note than the args.splice call is already used correctly when handling the `-f=a b c` case.


Patch:
diff --git a/index.js b/index.js
index 0442922..2a261cb 100644
--- a/index.js
+++ b/index.js
@@ -121,11 +121,11 @@ function parse (args, opts) {
 
       // nargs format = '--f=monkey washing cat'
       if (checkAllAliases(m[1], flags.nargs)) {
-        args.splice(i + 1, m[1], m[2])
+        args.splice(i + 1, 0, m[2])
         i = eatNargs(i, m[1], args)
       // arrays format = '--f=a b c'
       } else if (checkAllAliases(m[1], flags.arrays) && args.length > i + 1) {
-        args.splice(i + 1, m[1], m[2])
+        args.splice(i + 1, 0, m[2])
         i = eatArray(i, m[1], args)
       } else {
         setArg(m[1], m[2])


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index fdc75fa..05aa341 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -1217,6 +1217,17 @@ describe('yargs-parser', function () {
       result.bar.should.include('cat')
       result.bar.should.include('dog')
     })
+
+    // see: https://github.com/yargs/yargs-parser/pull/13
+    it('should support array for --foo= format when the key is a number', function () {
+      var result = parser(['--1=a', 'b'], {
+        array: ['1']
+      })
+
+      Array.isArray(result['1']).should.equal(true)
+      result['1'][0].should.equal('a')
+      result['1'][1].should.equal('b')
+    })
   })
 
   describe('nargs', function () {
@@ -1318,6 +1329,19 @@ describe('yargs-parser', function () {
       result.bar.should.equal('banana')
       result.f.should.equal(true)
     })
+
+    // see: https://github.com/yargs/yargs-parser/pull/13
+    it('should support nargs for --foo= format when the key is a number', function () {
+      var result = parser(['--1=a', 'b'], {
+        narg: {
+          1: 2
+        }
+      })
+
+      Array.isArray(result['1']).should.equal(true)
+      result['1'][0].should.equal('a')
+      result['1'][1].should.equal('b')
+    })
   })
 
   describe('env vars', function () {
Repository: yargs/yargs-parser
Pull request #17 (2016-04-02 23:24:26)

Fix Boolean flag when next value contains the strings 'true' or 'false'
When calling `test.js -b aaafalseaaa`, and `b` is a boolean, the value of `'b'` is set to `false` and `'aaafalseaaa'` doesn't appear in `'_'`.

I fixed this by updating the regex to look like the one in the `--foo true` case, where it works fine.


coveralls: 
[![Coverage Status](https://coveralls.io/builds/5641737/badge)](https://coveralls.io/builds/5641737)

Coverage remained the same at 100.0% when pulling **ca533db2e42dd20c361cb5c1e11e9d216c072e7b on elas7:fix-bool** into **48b1e6a338f80417b3fd0fc3e39ae181332fdcb5 on yargs:master**.

bcoe: @elas7 mind rebasing 👍 
coveralls: 
[![Coverage Status](https://coveralls.io/builds/5725124/badge)](https://coveralls.io/builds/5725124)

Coverage remained the same at 100.0% when pulling **69b18db53f9ab09719f0599f34d5aac001f3521c on elas7:fix-bool** into **90b871f387fbcbe976c9503aefe3b04f2f14daf1 on yargs:master**.

bcoe: great fix 👍 

Patch:
diff --git a/index.js b/index.js
index 4a50d6a..42dac4d 100644
--- a/index.js
+++ b/index.js
@@ -245,7 +245,7 @@ function parse (args, opts) {
             !checkAllAliases(key, flags.counts)) {
             setArg(key, next)
             i++
-          } else if (/true|false/.test(next)) {
+          } else if (/^(true|false)$/.test(next)) {
             setArg(key, next)
             i++
           } else {


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index a602742..338aea0 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -153,6 +153,15 @@ describe('yargs-parser', function () {
     parse.should.have.property('_').and.deep.equal(['moo'])
   })
 
+  it('should not set boolean options values if the next value only contains the words "true" or "false"', function () {
+    var parse = parser(['--verbose', 'aaatrueaaa', 'moo', '-t', 'aaafalseaaa'], {
+      boolean: ['t', 'verbose']
+    })
+    parse.should.have.property('verbose', true).and.be.a('boolean')
+    parse.should.have.property('t', true).and.be.a('boolean')
+    parse.should.have.property('_').and.deep.equal(['aaatrueaaa', 'moo', 'aaafalseaaa'])
+  })
+
   it('should allow defining options as boolean in groups', function () {
     var parse = parser([ '-x', '-z', 'one', 'two', 'three' ], {
       boolean: ['x', 'y', 'z']
Repository: yargs/yargs-parser
Pull request #63 (2016-10-15 09:52:08)

fix: handle dot notation boolean options
Fixes yargs/yargs#617

On studying the code I found that this bug is being caused by yargs-parser. I think my fix should solve this issue, though I'm not sure if something else breaks because of these changes.

I've tested this modified library with yargs and found that all test cases pass.


bcoe: @ssonal appreciate this patch, sorry for the slow turn around. Will hopefully have time to do a tiny bit of OSSing this weekend.

Patch:
diff --git a/index.js b/index.js
index 564cb2e..8eecb62 100644
--- a/index.js
+++ b/index.js
@@ -540,7 +540,7 @@ function parse (args, opts) {
       o[key] = increment(o[key])
     } else if (o[key] === undefined && checkAllAliases(key, flags.arrays)) {
       o[key] = Array.isArray(value) ? value : [value]
-    } else if (o[key] === undefined || checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) {
+    } else if (o[key] === undefined || checkAllAliases(key, flags.bools) || checkAllAliases(keys.join('.'), flags.bools) || checkAllAliases(key, flags.counts)) {
       o[key] = value
     } else if (Array.isArray(o[key])) {
       o[key].push(value)


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index dac993c..f4fbeb7 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -198,6 +198,18 @@ describe('yargs-parser', function () {
     parse.should.have.property('_').and.deep.equal(['one', 'two', 'three'])
   })
 
+  it('should correctly parse dot-notation boolean flags', function () {
+    var parse = parser(['--nested', '--n.v', '--n.y', 'foo'], {
+      boolean: ['nested', 'n.v']
+    })
+
+    parse.should.have.property('nested', true).and.be.a('boolean')
+    parse.should.have.property('n').and.deep.equal({
+      v: true,
+      y: 'foo'
+    })
+  })
+
   it('should preserve newlines in option values', function () {
     var args = parser(['-s', 'X\nX'])
     args.should.have.property('_').with.length(0)
Repository: yargs/yargs-parser
Pull request #65 (2016-11-04 17:53:09)

fix: apply coercions to default options
Fixes yargs/yargs#598


Patch:
diff --git a/index.js b/index.js
index 564cb2e..0d3ed26 100644
--- a/index.js
+++ b/index.js
@@ -279,8 +279,8 @@ function parse (args, opts) {
   setConfig(argv)
   setConfigObjects()
   applyEnvVars(argv, false)
-  applyCoercions(argv)
   applyDefaultsAndAliases(argv, flags.aliases, defaults)
+  applyCoercions(argv)
 
   // for any counts either not in args or without an explicit default, set to 0
   Object.keys(flags.counts).forEach(function (key) {
@@ -540,7 +540,7 @@ function parse (args, opts) {
       o[key] = increment(o[key])
     } else if (o[key] === undefined && checkAllAliases(key, flags.arrays)) {
       o[key] = Array.isArray(value) ? value : [value]
-    } else if (o[key] === undefined || checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) {
+    } else if (o[key] === undefined || checkAllAliases(key, flags.bools) || checkAllAliases(keys.join('.'), flags.bools) || checkAllAliases(key, flags.counts)) {
       o[key] = value
     } else if (Array.isArray(o[key])) {
       o[key].push(value)


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index dac993c..8529d85 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -198,6 +198,18 @@ describe('yargs-parser', function () {
     parse.should.have.property('_').and.deep.equal(['one', 'two', 'three'])
   })
 
+  it('should correctly parse dot-notation boolean flags', function () {
+    var parse = parser(['--nested', '--n.v', '--n.y', 'foo'], {
+      boolean: ['nested', 'n.v']
+    })
+
+    parse.should.have.property('nested', true).and.be.a('boolean')
+    parse.should.have.property('n').and.deep.equal({
+      v: true,
+      y: 'foo'
+    })
+  })
+
   it('should preserve newlines in option values', function () {
     var args = parser(['-s', 'X\nX'])
     args.should.have.property('_').with.length(0)
@@ -1992,6 +2004,18 @@ describe('yargs-parser', function () {
       parsed.foo.bar.should.equal('nananana, batman!')
     })
 
+    it('applies coercion to defaults', function () {
+      var parsed = parser([], {
+        default: { foo: 'bar' },
+        coerce: {
+          foo: function (val) {
+            return val.toUpperCase()
+          }
+        }
+      })
+      parsed.foo.should.equal('BAR')
+    })
+
     it('applies coercion function to an implicit array', function () {
       var parsed = parser(['--foo', '99', '-f', '33'], {
         coerce: {
Repository: yargs/yargs-parser
Pull request #72 (2016-11-28 04:06:03)

fix: inner objects in configs had their keys appended to top-level key when dot-notation was disabled
edge case discussed in https://github.com/yargs/yargs/issues/716


Patch:
diff --git a/index.js b/index.js
index 1031bf0..cdb5fc5 100644
--- a/index.js
+++ b/index.js
@@ -452,7 +452,10 @@ function parse (args, opts) {
       var value = config[key]
       var fullKey = prev ? prev + '.' + key : key
 
-      if (Object.prototype.toString.call(value) === '[object Object]') {
+      // if the value is an inner object and we have dot-notation
+      // enabled, treat inner objects in config the same as
+      // heavily nested dot notations (foo.bar.apple).
+      if (typeof value === 'object' && !Array.isArray(value) && configuration['dot-notation']) {
         // if the value is an object but not an array, check nested object
         setConfigObject(value, fullKey)
       } else {


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index 0e1778a..5d4243a 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -1886,6 +1886,31 @@ describe('yargs-parser', function () {
         expect(parsed['foo.bar']).to.equal('banana')
         expect(parsed).not.to.include.keys('f.bar')
       })
+
+      // addresses https://github.com/yargs/yargs/issues/716
+      it('does not append nested-object keys from config to top-level key', function () {
+        var parsed = parser([], {
+          alias: {
+            'foo': ['f']
+          },
+          configuration: {
+            'dot-notation': false
+          },
+          configObjects: [
+            {
+              'website.com': {
+                a: 'b',
+                b: 'c'
+              }
+            }
+          ]
+        })
+
+        parsed['website.com'].should.deep.equal({
+          a: 'b',
+          b: 'c'
+        })
+      })
     })
 
     describe('parse numbers', function () {
Repository: yargs/yargs-parser
Pull request #81 (2017-02-18 19:42:13)

fix: environment variables should take precedence over config file
BREAKING CHANGE: environment variables now take precedence over config file values.

see: https://github.com/yargs/yargs/issues/627

CC: @jaridmargolin


Patch:
diff --git a/index.js b/index.js
index 1a04d55..b71faf5 100644
--- a/index.js
+++ b/index.js
@@ -273,14 +273,14 @@ function parse (args, opts) {
 
   // order of precedence:
   // 1. command line arg
-  // 2. value from config file
-  // 3. value from config objects
-  // 4. value from env var
+  // 2. value from env var
+  // 3. value from config file
+  // 4. value from config objects
   // 5. configured default value
   applyEnvVars(argv, true) // special case: check env vars that point to config file
+  applyEnvVars(argv, false)
   setConfig(argv)
   setConfigObjects()
-  applyEnvVars(argv, false)
   applyDefaultsAndAliases(argv, flags.aliases, defaults)
   applyCoercions(argv)
 


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index c9c5999..5b59c61 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -1697,7 +1697,7 @@ describe('yargs-parser', function () {
     })
 
     var jsonPath = path.resolve(__dirname, './fixtures/config.json')
-    it('should prefer config file value over env var', function () {
+    it('should prefer environment variables over config file', function () {
       process.env.CFG_HERP = 'zerp'
       var result = parser(['--cfg', jsonPath], {
         envPrefix: 'CFG',
@@ -1708,7 +1708,7 @@ describe('yargs-parser', function () {
         }
       })
 
-      result.herp.should.equal('derp')
+      result.herp.should.equal('zerp')
     })
 
     it('should support an env var value as config file option', function () {
Repository: yargs/yargs-parser
Pull request #90 (2017-05-01 05:54:37)

fix: default '--' to undefined, allowing for smoother transition in yargs
we should be defaulting `--` to `undefined`, rather than an empty array; this behavior is closer to how the `array` type works.


Patch:
diff --git a/index.js b/index.js
index 5276306..15936de 100644
--- a/index.js
+++ b/index.js
@@ -101,10 +101,6 @@ function parse (args, opts) {
 
   var argv = { _: [] }
 
-  if (notFlagsOption) {
-    argv[notFlagsArgv] = []
-  }
-
   Object.keys(flags.bools).forEach(function (key) {
     setArg(key, !(key in defaults) ? false : defaults[key])
     setDefaulted(key)
@@ -296,6 +292,8 @@ function parse (args, opts) {
     if (!hasKey(argv, key.split('.'))) setArg(key, 0)
   })
 
+  // '--' defaults to undefined.
+  if (notFlagsOption && notFlags.length) argv[notFlagsArgv] = []
   notFlags.forEach(function (key) {
     argv[notFlagsArgv].push(key)
   })


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index 02fb779..23c8e64 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -10,12 +10,14 @@ var path = require('path')
 describe('yargs-parser', function () {
   it('should parse a "short boolean"', function () {
     var parse = parser([ '-b' ])
+    parse.should.not.have.property('--')
     parse.should.have.property('b').to.be.ok.and.be.a('boolean')
     parse.should.have.property('_').with.length(0)
   })
 
   it('should parse a "long boolean"', function () {
     var parse = parser('--bool')
+    parse.should.not.have.property('--')
     parse.should.have.property('bool', true)
     parse.should.have.property('_').with.length(0)
   })
@@ -113,6 +115,16 @@ describe('yargs-parser', function () {
     parse.should.have.property('_').and.deep.equal(['bare', '--not-a-flag', '-', '-h', '-multi', '--', 'eek'])
   })
 
+  it('should not populate "--" if parsing was not stopped', function () {
+    var parse = parser([ '-b' ])
+    parse.should.not.have.property('--')
+  })
+
+  it('should populate "--" if parsing is stopped', function () {
+    var parse = parser([ '-b', '--', 'foo bar' ])
+    parse.should.have.property('--')
+  })
+
   it('should parse numbers appropriately', function () {
     var argv = parser([
       '-x', '1234',
Repository: yargs/yargs-parser
Pull request #91 (2017-05-02 05:49:45)

chore: revert populate-- logic
BREAKING CHANGE: populate-- defaults to false, based on discussion at npm today.


Patch:
diff --git a/README.md b/README.md
index a3305d4..d1817fc 100644
--- a/README.md
+++ b/README.md
@@ -250,13 +250,15 @@ node example.js -x 1 2 -x 3 4
 { _: [], x: [[1, 2], [3, 4]] }
 ```
 
-### `populate--`
+### populate --
 
-* default: `true`.
+* default: `false`.
+* key: `populate--`
 
 Should unparsed flags be stored in `--` or `_`.
 
 _If disabled:_
+
 ```sh
 node example.js a -b -- x y
 { _: [ 'a', 'x', 'y' ], b: true }
diff --git a/index.js b/index.js
index 15936de..7315406 100644
--- a/index.js
+++ b/index.js
@@ -18,7 +18,7 @@ function parse (args, opts) {
     'boolean-negation': true,
     'duplicate-arguments-array': true,
     'flatten-duplicate-arrays': true,
-    'populate--': true
+    'populate--': false
   }, opts.configuration)
   var defaults = opts.default || {}
   var configObjects = opts.configObjects || []


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index 23c8e64..373f8d3 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -115,16 +115,6 @@ describe('yargs-parser', function () {
     parse.should.have.property('_').and.deep.equal(['bare', '--not-a-flag', '-', '-h', '-multi', '--', 'eek'])
   })
 
-  it('should not populate "--" if parsing was not stopped', function () {
-    var parse = parser([ '-b' ])
-    parse.should.not.have.property('--')
-  })
-
-  it('should populate "--" if parsing is stopped', function () {
-    var parse = parser([ '-b', '--', 'foo bar' ])
-    parse.should.have.property('--')
-  })
-
   it('should parse numbers appropriately', function () {
     var argv = parser([
       '-x', '1234',
@@ -2222,25 +2212,27 @@ describe('yargs-parser', function () {
     })
 
     describe('populate--', function () {
-      it('should populate "_" if "populate-- false', function () {
+      it('should populate "_" by default', function () {
         var result = parser([
           'bare',
           '--', '-h', 'eek', '--'
-        ], {
-          configuration: {'populate--': false}
-        })
+        ])
         result.should.have.property('_').and.deep.equal(['bare', '-h', 'eek', '--'])
         result.should.not.have.property('--')
       })
 
-      it('should populate the "--" array by default', function () {
+      it('should populate the "--" if populate-- is "true"', function () {
         var result = parser([
           '--name=meowmers', 'bare', '-cats', 'woo', 'moxy',
           '-h', 'awesome', '--multi=quux',
           '--key', 'value',
           '-b', '--bool', '--no-meep', '--multi=baz',
           '--', '--not-a-flag', '-', '-h', '-multi', '--', 'eek'
-        ])
+        ], {
+          configuration: {
+            'populate--': true
+          }
+        })
         result.should.have.property('c', true)
         result.should.have.property('a', true)
         result.should.have.property('t', true)