fast-querystring
Advanced tools
Comparing version
@@ -28,7 +28,16 @@ "use strict"; | ||
if (c === 38 || isNaN(c)) { | ||
// Disallow empty key values. | ||
if (equalityIndex - separatorIndex > 0 && i - equalityIndex + 1 > 0) { | ||
key = input.slice(separatorIndex, equalityIndex); | ||
value = input.slice(equalityIndex + 1, i); | ||
const hasOnlyKey = equalityIndex <= separatorIndex; | ||
const keySize = | ||
hasOnlyKey ? i - separatorIndex : equalityIndex - separatorIndex; | ||
if (keySize > 0) { | ||
// Accept empty values, if key size is positive | ||
if (hasOnlyKey) { | ||
key = input.slice(separatorIndex, i); | ||
value = ""; | ||
} else { | ||
key = input.slice(separatorIndex, equalityIndex); | ||
value = input.slice(equalityIndex + 1, i); | ||
} | ||
// Optimization: Replace '+' with space | ||
@@ -35,0 +44,0 @@ if (hasPlus) { |
{ | ||
"name": "fast-querystring", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
# fast-querystring | ||
Fast query-string parser to replace the deprecated `node:querystring` parse function. | ||
Fast query-string parser to replace the legacy `node:querystring` parse function. | ||
@@ -18,7 +18,5 @@ ### Installation | ||
- `foo=bar&foo=baz` parses into `{foo: ['bar', 'baz']}` | ||
- Supports pairs with missing values | ||
- `foo=bar&hola` parses into `{foo: 'bar', hola: ''}` | ||
### Differences | ||
- Key & value with length 0 is omitted by default | ||
- `foo=bar&hey` parses into `{foo: 'bar'}`, but `node:querystring` returns `{foo: 'bar', hey: ''}` | ||
### Usage | ||
@@ -25,0 +23,0 @@ |
7292
2.4%98
8.89%53
-3.64%