nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: unjs/ufo
Pull request #44 (2022-03-04 07:58:00)

fix(parseURL): respect 0 number as query value

aryraditya: hi @pi0 could you please check this ?
pi0: Thanks!

Patch:
diff --git a/src/query.ts b/src/query.ts
index fef425e..cdb6af7 100644
--- a/src/query.ts
+++ b/src/query.ts
@@ -5,7 +5,7 @@ import {
   encodeQueryValue
 } from './encoding'
 
-export type QueryValue = string | string[] | undefined
+export type QueryValue = string | string[] | number | number[] | undefined
 export type QueryObject = Record<string, QueryValue>
 
 export function parseQuery (paramsStr: string = ''): QueryObject {
@@ -35,7 +35,7 @@ export function parseQuery (paramsStr: string = ''): QueryObject {
 }
 
 export function encodeQueryItem (key: string, val: QueryValue): string {
-  if (!val) {
+  if (!val && val !== 0) {
     return encodeQueryKey(key)
   }
 


Test patch:
diff --git a/test/query.test.ts b/test/query.test.ts
index 714ec27..55cd3c7 100644
--- a/test/query.test.ts
+++ b/test/query.test.ts
@@ -7,6 +7,8 @@ describe('withQuery', () => {
     { input: '/', query: {}, out: '/' },
     { input: '?test', query: {}, out: '?test' },
     { input: '/?test', query: {}, out: '/?test' },
+    { input: '/?test', query: { foo: '0' }, out: '/?test&foo=0' },
+    { input: '/?test', query: { foo: 0 }, out: '/?test&foo=0' },
     { input: '/?test', query: { foo: 1 }, out: '/?test&foo=1' },
     { input: '/?foo=1', query: { foo: 2 }, out: '/?foo=2' },
     {
Repository: unjs/ufo
Pull request #51 (2022-03-30 22:09:00)

fix(encodeQueryItem): stringify boolean values
Handle boolean values in encodeQueryItem.

I was also wondering why not simply using the native URLSearchParams interface to encode query params ?


Patch:
diff --git a/src/query.ts b/src/query.ts
index 4207109..bbcec7f 100644
--- a/src/query.ts
+++ b/src/query.ts
@@ -35,7 +35,7 @@ export function parseQuery (paramsStr: string = ''): QueryObject {
 }
 
 export function encodeQueryItem (key: string, val: QueryValue): string {
-  if (typeof val === 'number') {
+  if (typeof val === 'number' || typeof val === 'boolean') {
     val = String(val)
   }
   if (!val) {


Test patch:
diff --git a/test/query.test.ts b/test/query.test.ts
index 55cd3c7..e4fecec 100644
--- a/test/query.test.ts
+++ b/test/query.test.ts
@@ -11,6 +11,7 @@ describe('withQuery', () => {
     { input: '/?test', query: { foo: 0 }, out: '/?test&foo=0' },
     { input: '/?test', query: { foo: 1 }, out: '/?test&foo=1' },
     { input: '/?foo=1', query: { foo: 2 }, out: '/?foo=2' },
+    { input: '/?foo=1', query: { foo: true, bar: false }, out: '/?foo=true&bar=false' },
     {
       input: '/',
       query: { email: 'some email.com' },
Repository: kkawakam/rustyline
Pull request #449 (2020-10-11 07:40:07)

Rustfmt


Patch:
diff --git a/src/keymap.rs b/src/keymap.rs
index da3feaa..0943849 100644
--- a/src/keymap.rs
+++ b/src/keymap.rs
@@ -109,14 +109,14 @@ pub enum Cmd {
     /// if cursor is in the middle of the text
     ///
     /// If you support multi-line input:
-    /// * Use `accept_in_the_middle: true` for mostly single-line cases,
-    ///   for example command-line.
-    /// * Use `accept_in_the_middle: false` for mostly multi-line cases,
-    ///   for example SQL or JSON input.
+    /// * Use `accept_in_the_middle: true` for mostly single-line cases, for
+    ///   example command-line.
+    /// * Use `accept_in_the_middle: false` for mostly multi-line cases, for
+    ///   example SQL or JSON input.
     AcceptOrInsertLine {
         /// Whether this commands accepts input if the cursor not at the end
         /// of the current input
-        accept_in_the_middle: bool
+        accept_in_the_middle: bool,
     },
 }
 
diff --git a/src/lib.rs b/src/lib.rs
index 273654b..673c504 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -603,16 +603,20 @@ fn readline_edit<H: Helper>(
                 let valid = s.validate()?;
                 let end = s.line.is_end_of_input();
                 match (cmd, valid, end) {
-                    | (Cmd::AcceptLine, _, _)
+                    (Cmd::AcceptLine, ..)
                     | (Cmd::AcceptOrInsertLine { .. }, true, true)
-                    | (Cmd::AcceptOrInsertLine { accept_in_the_middle: true }, true, _)
-                    => {
+                    | (
+                        Cmd::AcceptOrInsertLine {
+                            accept_in_the_middle: true,
+                        },
+                        true,
+                        _,
+                    ) => {
                         break;
                     }
-                    | (Cmd::Newline, _, _)
+                    (Cmd::Newline, ..)
                     | (Cmd::AcceptOrInsertLine { .. }, false, _)
-                    | (Cmd::AcceptOrInsertLine { .. }, true, false)
-                    => {
+                    | (Cmd::AcceptOrInsertLine { .. }, true, false) => {
                         s.edit_insert('\n', 1)?;
                     }
                     _ => unreachable!(),


Test patch:
diff --git a/src/test/mod.rs b/src/test/mod.rs
index 207597e..f89bcf5 100644
--- a/src/test/mod.rs
+++ b/src/test/mod.rs
@@ -62,7 +62,12 @@ fn complete_line() {
     let keys = vec![KeyPress::Enter];
     let mut rdr: IntoIter<KeyPress> = keys.into_iter();
     let cmd = super::complete_line(&mut rdr, &mut s, &mut input_state, &Config::default()).unwrap();
-    assert_eq!(Some(Cmd::AcceptOrInsertLine { accept_in_the_middle: true }), cmd);
+    assert_eq!(
+        Some(Cmd::AcceptOrInsertLine {
+            accept_in_the_middle: true
+        }),
+        cmd
+    );
     assert_eq!("rust", s.line.as_str());
     assert_eq!(4, s.line.pos());
 }