nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: koajs/koa
Pull request #480 (2015-09-20 06:25:39)

implement ctx.origin
implement `ctx.origin` for #476


Patch:
diff --git a/lib/context.js b/lib/context.js
index fa13a71..6fe17c3 100644
--- a/lib/context.js
+++ b/lib/context.js
@@ -176,6 +176,7 @@ delegate(proto, 'request')
   .access('query')
   .access('path')
   .access('url')
+  .getter('origin')
   .getter('href')
   .getter('subdomains')
   .getter('protocol')
diff --git a/lib/request.js b/lib/request.js
index 3e0956a..12a92e0 100644
--- a/lib/request.js
+++ b/lib/request.js
@@ -59,6 +59,17 @@ module.exports = {
     this.req.url = val;
   },
 
+  /**
+   * Get origin of URL.
+   *
+   * @return {String}
+   * @api public
+   */
+
+  get origin() {
+    return this.protocol + '://' + this.host;
+  },
+
   /**
    * Get full request URL.
    *
@@ -71,7 +82,7 @@ module.exports = {
     if (/^https?:\/\//i.test(this.originalUrl)) {
       return this.originalUrl;
     }
-    return this.protocol + '://' + this.host + this.originalUrl;
+    return this.origin + this.originalUrl;
   },
 
   /**


Test patch:
diff --git a/test/request/origin.js b/test/request/origin.js
new file mode 100644
index 0000000..8c1081f
--- /dev/null
+++ b/test/request/origin.js
@@ -0,0 +1,24 @@
+
+var Stream = require('stream');
+var http = require('http');
+var koa = require('../../');
+var context = require('../context');
+
+describe('ctx.origin', function(){
+  it('should return the origin of url', function(){
+    var socket = new Stream.Duplex();
+    var req = {
+      url: '/users/1?next=/dashboard',
+      headers: {
+        host: 'localhost'
+      },
+      socket: socket,
+      __proto__: Stream.Readable.prototype
+    };
+    var ctx = context(req);
+    ctx.origin.should.equal('http://localhost');
+    // change it also work
+    ctx.url = '/foo/users/1?next=/dashboard';
+    ctx.origin.should.equal('http://localhost');
+  })
+})
Repository: koajs/koa
Pull request #809 (2016-09-07 06:43:47)

fix: should get subdomains from hostname instead
This helps avoid dealing with the port in this.host

codecov-io: ## [Current coverage](https://codecov.io/gh/koajs/koa/pull/809?src=pr) is 100% (diff: 100%)
> Merging [#809](https://codecov.io/gh/koajs/koa/pull/809?src=pr) into [master](https://codecov.io/gh/koajs/koa/branch/master?src=pr) will not change coverage

```diff
@@           master   #809   diff @@
====================================
  Files           4      4          
  Lines         417    417          
  Methods        81     81          
  Messages        0      0          
  Branches      103    102     -1   
====================================
  Hits          417    417          
  Misses          0      0          
  Partials        0      0          
```

> Powered by [Codecov](https://codecov.io?src=pr). Last update [4c665cc...0981a6d](https://codecov.io/gh/koajs/koa/compare/4c665cc2ef68e9943515c26aedb0c04598e3f13e...0981a6dcf873e86fbe2001a84fbea19797448a8c?src=pr)

Patch:
diff --git a/lib/request.js b/lib/request.js
index 830b21b..d1a73ff 100644
--- a/lib/request.js
+++ b/lib/request.js
@@ -418,9 +418,9 @@ module.exports = {
 
   get subdomains() {
     var offset = this.app.subdomainOffset;
-    var host = this.host || '';
-    if (net.isIP(host)) return [];
-    return host
+    var hostname = this.hostname;
+    if (net.isIP(hostname)) return [];
+    return hostname
       .split('.')
       .reverse()
       .slice(offset);


Test patch:
diff --git a/test/request/subdomains.js b/test/request/subdomains.js
index 39b4b6b..767a6cb 100644
--- a/test/request/subdomains.js
+++ b/test/request/subdomains.js
@@ -19,9 +19,9 @@ describe('req.subdomains', function(){
     req.subdomains.should.eql([]);
   })
 
-  it('should check if the host is an ip address', function(){
+  it('should check if the host is an ip address, even with a port', function(){
     var req = request();
-    req.header.host = '127.0.0.1';
+    req.header.host = '127.0.0.1:3000';
     req.subdomains.should.eql([]);
   });
 })
Repository: 3Hren/msgpack-rust
Pull request #224 (2019-11-14 05:44:51)

square bracket indexing of maps (e.g. val["key"])
Consider the use case of json data.

Here is an implementation of val["key"] indexing of maps, and some tests which show results similar to the existing tests for indexing arrays.

This is incomplete (it doesn't support String as an index, among others).
It's verbose for the sake of discussion, and would be more consistent with existing code if it used iterators.

As it stands, this is just an example as a suggestion.


Patch:
diff --git a/rmpv/src/lib.rs b/rmpv/src/lib.rs
index 3da4e6e..6e63562 100644
--- a/rmpv/src/lib.rs
+++ b/rmpv/src/lib.rs
@@ -847,6 +847,27 @@ impl Index<usize> for Value {
     }
 }
 
+impl Index<&str> for Value {
+    type Output = Value;
+    fn index(&self, index: &str) -> &Value {
+        if let Value::Map(ref map) = *self {
+            if let Some(found) = map.iter().find(
+                |(key, _val)|  {
+                if let Value::String(ref strval) = *key {
+                    if let Some(s) = strval.as_str() {
+                        if s == index { return true; }
+                    }
+                }
+                return false;
+                })
+            {
+                return &found.1;
+            }
+        }
+        &NIL
+    }
+}
+
 impl From<bool> for Value {
     fn from(v: bool) -> Self {
         Value::Boolean(v)


Test patch:
diff --git a/rmpv/tests/value.rs b/rmpv/tests/value.rs
index 10df32f..c035310 100644
--- a/rmpv/tests/value.rs
+++ b/rmpv/tests/value.rs
@@ -146,3 +146,24 @@ fn monadic_index() {
     assert!(val[2].is_nil());
     assert!(val[1][2][3][4][5].is_nil());
 }
+
+#[test]
+fn index_into_map() {
+    let val = Value::Map(vec![
+        ( Value::String("a".into()), Value::from(1) ),
+        ( Value::String("b".into()), Value::Array(vec![
+            Value::from(3),
+            Value::from(4),
+            Value::from(5)
+        ])),
+        ( Value::String("c".into()), Value::Map(vec![
+            ( Value::String("d".into()), Value::from(8) ),
+            ( Value::String("e".into()), Value::from(9) )
+        ]))
+    ]);        
+    assert_eq!(1, val["a"].as_i64().unwrap());
+    assert_eq!(5, val["b"][2].as_i64().unwrap());
+    assert_eq!(9, val["c"]["e"].as_i64().unwrap());
+    assert!(val["b"][3].is_nil());
+    assert!(val["d"][4].is_nil());
+}
Repository: 3Hren/msgpack-rust
Pull request #230 (2019-12-30 17:35:14)

Implement TryInto<String> for Value
I missed that with the last PR, but it's actually the most important part imho :)

It might also be implemented for `Utf8String`, but it would make most sense with `type Error = (Vec<u8>, Uf8Error)`, and I wasn't sure if you wanted to expose the internal details of this type.

Let me know what you think :)

kornelski: As far as I can see Rust stdlib doesn't have `TryFrom` for `Vec<u8>` to `String`, so it may be OK to keep it utf8-string-only.

Patch:
diff --git a/rmpv/src/lib.rs b/rmpv/src/lib.rs
index acd5206..363d2ac 100644
--- a/rmpv/src/lib.rs
+++ b/rmpv/src/lib.rs
@@ -1056,6 +1056,19 @@ impl TryFrom<Value> for f64 {
       }
   }
 }
+
+impl TryFrom<Value> for String {
+  type Error = Value;
+
+  fn try_from(val: Value) -> Result<Self, Self::Error> {
+    match val {
+      Value::String(Utf8String{ s: Ok(u)}) => {
+        Ok(u)
+      }
+      _ => Err(val)
+    }
+  }
+}
 // The following impl was left out intentionally, see
 // https://github.com/3Hren/msgpack-rust/pull/228#discussion_r359513925
 /*


Test patch:
diff --git a/rmpv/tests/value.rs b/rmpv/tests/value.rs
index b3de5e7..6c383b7 100644
--- a/rmpv/tests/value.rs
+++ b/rmpv/tests/value.rs
@@ -193,5 +193,6 @@ fn try_from_val() {
 
   assert_eq!(false, Value::Boolean(false).try_into().unwrap());
   assert_eq!(Utf8String::from("spook"), Value::from("spook").try_into().unwrap());
+  assert_eq!(String::from("spook"), TryInto::<String>::try_into(Value::from("spook")).unwrap());
   assert_eq!(vec![0], TryInto::<Vec<u8>>::try_into(Value::Binary(vec![0u8])).unwrap());
 }
Repository: 3Hren/msgpack-rust
Pull request #241 (2020-02-12 12:30:45)

Fix compat break from new type arg


Patch:
diff --git a/rmp-serde/Cargo.toml b/rmp-serde/Cargo.toml
index 21ec513..ad7140e 100644
--- a/rmp-serde/Cargo.toml
+++ b/rmp-serde/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "rmp-serde"
-version = "0.14.2"
+version = "0.14.3"
 authors = ["Evgeny Safronov <division494@gmail.com>"]
 license = "MIT"
 description = "Serde bindings for RMP"
diff --git a/rmp-serde/src/encode.rs b/rmp-serde/src/encode.rs
index 91ff100..736835d 100644
--- a/rmp-serde/src/encode.rs
+++ b/rmp-serde/src/encode.rs
@@ -117,7 +117,7 @@ pub trait UnderlyingWrite {
 /// operation is retried.
 // TODO: Docs. Examples.
 #[derive(Debug)]
-pub struct Serializer<W, C> {
+pub struct Serializer<W, C = DefaultConfig> {
     wr: W,
     config: C,
     depth: usize,


Test patch:
diff --git a/rmp-serde/tests/encode.rs b/rmp-serde/tests/encode.rs
index 21337c9..3a3a8f1 100644
--- a/rmp-serde/tests/encode.rs
+++ b/rmp-serde/tests/encode.rs
@@ -361,3 +361,8 @@ fn pass_raw_ref_invalid_utf8() {
 
     assert_eq!(vec![0xa4, 0x92, 0xcc, 0xc8, 0x90], buf);
 }
+
+#[test]
+fn serializer_one_type_arg() {
+    let _s: rmp_serde::Serializer<&mut dyn std::io::Write>;
+}
Repository: 3Hren/msgpack-rust
Pull request #251 (2020-07-24 20:14:38)

Maintenance status


Patch:
diff --git a/rmp-serde/Cargo.toml b/rmp-serde/Cargo.toml
index ad7140e..71c4b26 100644
--- a/rmp-serde/Cargo.toml
+++ b/rmp-serde/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "rmp-serde"
-version = "0.14.3"
+version = "0.14.4"
 authors = ["Evgeny Safronov <division494@gmail.com>"]
 license = "MIT"
 description = "Serde bindings for RMP"
@@ -17,5 +17,9 @@ serde = "1.0.99"
 rmp = { version = "0.8.8", path = "../rmp" }
 
 [dev-dependencies]
+rmpv = { path = "../rmpv" }
 serde_bytes = "0.11.2"
 serde_derive = "1.0.99"
+
+[badges]
+maintenance = { status = "passively-maintained" }
diff --git a/rmp/Cargo.toml b/rmp/Cargo.toml
index 757de15..863ec64 100644
--- a/rmp/Cargo.toml
+++ b/rmp/Cargo.toml
@@ -17,3 +17,6 @@ num-traits = "0.2.8"
 
 [dev-dependencies]
 quickcheck = "0.9"
+
+[badges]
+maintenance = { status = "passively-maintained" }
diff --git a/rmpv/Cargo.toml b/rmpv/Cargo.toml
index 9fcce2e..3765215 100644
--- a/rmpv/Cargo.toml
+++ b/rmpv/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "rmpv"
-version = "0.4.4"
+version = "0.4.5"
 authors = ["Evgeny Safronov <division494@gmail.com>"]
 license = "MIT"
 description = "Value variant for RMP"


Test patch:
diff --git a/rmp-serde/tests/round.rs b/rmp-serde/tests/round.rs
index 8a55b66..a042a7f 100644
--- a/rmp-serde/tests/round.rs
+++ b/rmp-serde/tests/round.rs
@@ -399,9 +399,22 @@ fn roundtrip_some() {
     assert_roundtrips(Some("hi".to_string()));
 }
 
+#[ignore]
+#[test]
+fn roundtrip_some_failures() {
+    // FIXME
+    assert_roundtrips(Err::<(),_>(222));
+    assert_roundtrips(Some(None::<()>));
+}
+
 #[cfg(test)]
 fn assert_roundtrips<T: PartialEq + std::fmt::Debug + Serialize + for<'a> Deserialize<'a>>(val: T) {
     let seriaized = rmp_serde::to_vec(&val).unwrap();
-    let val2: T = rmp_serde::from_slice(&seriaized).unwrap();
+    let val2: T = match rmp_serde::from_slice(&seriaized) {
+        Ok(t) => t,
+        Err(e) => {
+            panic!("Does not deserialize: {}\nSerialized {:?}\nGot {:?}\n", e, val, rmpv::decode::value::read_value(&mut seriaized.as_slice()).expect("rmp didn't serialize corerctly at all"));
+        },
+    };
     assert_eq!(val2, val);
 }