Skip to content

Commit 732e0b0

Browse files
committed
Improve handling of partially parseable query strings
Previously we assumed that if qs.stringify didn't match the query string, then the queryString & queryObj properties would be empty, and so leaving the querystring in the URL (basically disabling structured generation of query = { a: b } style code and using raw URLs instead) would be safe. It turns out though that for partially parseable cases, we can get HARs with a URL containing a broken query string _and_ a valid queryString property with some values in it. We now actively ignore the latter, so the URL as always used as-is.
1 parent f00b01b commit 732e0b0

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,11 @@ HTTPSnippet.prototype.prepare = function (request) {
242242
request.uriObj.path = request.uriObj.pathname + '?' + request.uriObj.search
243243
}
244244
} else {
245-
// We have no request.queryObj (so snippets won't send query params in a structured way)
246-
// We keep the queryString in request.url (so it's sent raw everywhere)
245+
// We keep the queryString in request.url (so it's sent raw everywhere) but disable it
246+
// elsewhere, so it's omitted from automatic code generation cases.
247247
// request.fullUrl is recreated below (maybe mild fixed?) but preserves raw search etc
248+
request.queryString = []
249+
request.queryObj = {}
248250
}
249251

250252
// construct a full url
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"method": "GET",
33
"url": "http://mockbin.com/har?&&a=b&&",
4-
"httpVersion": "HTTP/1.1",
5-
"queryString": []
4+
"queryString": [
5+
{
6+
"name": "a",
7+
"value": "b"
8+
}
9+
],
10+
"httpVersion": "HTTP/1.1"
611
}

0 commit comments

Comments
 (0)