Repository: codecov/uploader (ts)

Issue:
`generateQuery` does not encode query strings
Use the native [URLSearchParams](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) API as an abstraction for handling query strings. It both formats and encodes/decodes query strings.

The current tests for `generateQuery` appear to validate the return values against malformed URIs (e.g., slashes and whatnot are not encoded properly). In other words, any refactor to `generateQuery` will have to correct the tests.

Pull request description:
Encode query strings
Fixes #255

Patch:
diff --git a/src/helpers/web.ts b/src/helpers/web.ts
index f7de0b8..8131991 100644
--- a/src/helpers/web.ts
+++ b/src/helpers/web.ts
@@ -114,9 +114,9 @@ export function generateQuery(queryParams: IServiceParams): string {
   if (queryParams.pr === 0  || isNaN(Number(queryParams.pr))) {
     queryParams.pr = ''
   }
-  return Object.entries(queryParams)
-    .map(([key, value]) => `${snakeCase(key)}=${value}`)
-    .join('&')
+  return new URLSearchParams(Object.entries(queryParams)
+    .map(([key, value]) => [snakeCase(key), value])
+  ).toString()
 }
 
 export function parsePOSTResults(uploadURL: string): {


Test patch:
diff --git a/test/helpers/web.test.ts b/test/helpers/web.test.ts
index 72af2bc..a3d1b26 100644
--- a/test/helpers/web.test.ts
+++ b/test/helpers/web.test.ts
@@ -89,7 +89,7 @@ describe('Web Helpers', () => {
       job: '6',
     }
     expect(generateQuery(queryParams)).toBe(
-      'branch=testBranch&commit=commitSHA&build=4&build_url=https://ci-providor.local/job/xyz&name=testName&tag=tagV1&slug=testOrg/testRepo&service=testingCI&flags=unit,uploader&pr=2&job=6',
+      'branch=testBranch&commit=commitSHA&build=4&build_url=https%3A%2F%2Fci-providor.local%2Fjob%2Fxyz&name=testName&tag=tagV1&slug=testOrg%2FtestRepo&service=testingCI&flags=unit%2Cuploader&pr=2&job=6',
     )
   })
 
@@ -108,7 +108,7 @@ describe('Web Helpers', () => {
       job: '6',
     }
     expect(generateQuery(queryParams)).toBe(
-      'branch=testBranch&commit=commitSHA&build=4&build_url=https://ci-providor.local/job/xyz&name=testName&tag=tagV1&slug=testOrg/testRepo&service=testingCI&flags=unit,uploader&pr=&job=6',
+      'branch=testBranch&commit=commitSHA&build=4&build_url=https%3A%2F%2Fci-providor.local%2Fjob%2Fxyz&name=testName&tag=tagV1&slug=testOrg%2FtestRepo&service=testingCI&flags=unit%2Cuploader&pr=&job=6',
     )
   })