title: AWS Gateway + x-www-form-urlencoded breaks with empty field
body: <p>I followed this awesome resource here -- <a href="https://forums.aws.amazon.com/thread.jspa?messageID=673012" rel="nofollow">https://forums.aws.amazon.com/thread.jspa?messageID=673012</a> -- but it throws an internal server error if the data has empty fields (which mine will, and its beyond my control).</p>
  
  <p>Then went searching and implemented this more recently updated library from Christian E Willman - <a href="https://github.com/christianewillman/aws-api-gateway-bodyparser" rel="nofollow">https://github.com/christianewillman/aws-api-gateway-bodyparser</a></p>
  
  <p>Despite being more terse, it's still failing when I send empty fields (via Postman). Any tips on getting it working would be greatly appreciated!</p>
  
  <p>Here's the mapping template for reference:</p>
  
  <pre><code>## Parses x-www-urlencoded data to JSON for AWS' API Gateway
  ##
  ## Author: Christian E Willman &lt;christian@willman.io&gt;
  
  #if ( $context.httpMethod == "POST" )
    #set( $requestBody = $input.path('$') )
  #else
    #set( $requestBody = "" )
  #end
  
  #set( $keyValuePairs = $requestBody.split("&amp;") )
  #set( $params = [] )
  
  ## Filter empty key-value pairs
  #foreach( $kvp in $keyValuePairs )
    #set( $operands = $kvp.split("=") )
  
    #if( $operands.size() == 1 || $operands.size() == 2 )
      #set( $success = $params.add($operands) )
    #end
  #end
  
  {
    ## add in the API stage data
    "stage": "$context.stage",
    #foreach( $param in $params )
      #set( $key = $util.urlDecode($param[0]) )
  
      #if( $param.size() &gt; 1 )
        #set( $value = $util.urlDecode($param[1]) )
      #else
        #set( $value = "" )
      #end
  
      "$key": "$value"#if( $foreach.hasNext ),#end
    #end
  }
  </code></pre>
  
  <p>Edit: This is the data I'm sending in:</p>
  
  <pre><code>WSO_SIGNATURE=1d9ce78c2778ecf795a93009a09f8102dd4ef38a&amp;WP_BUYER_NAME=Neil+calabroso&amp;WP_ITEM_NAME=Welcome+to+the+Vault&amp;SHIPTONAME=Neil+calabroso&amp;WSO_PRODUCT_ID=wp_product_3&amp;WP_AFFID=&amp;WSO_SALE_CURRENCY=USD&amp;EMAIL=nn%2Bpaypal%40freelancer.com&amp;WP_ITEM_NUMBER=wp_product_3&amp;PAYMENTSTATUS=COMPLETED&amp;WP_BUYER_EMAIL=nn%2Bpaypal%40freelancer.com&amp;WSO_PRODUCT_NAME=Welcome+to+the+Vault&amp;WP_SALEID=wp_sale_3&amp;AMT=43&amp;WSO_CUSTOMER_EMAIL=nn%2Bpaypal%40freelancer.com&amp;WSO_SALE_ACTION=SALE&amp;WP_SALE_AMOUNT=43&amp;WSO_TXN_ID=35&amp;saleid=wp_sale_3&amp;WSO_AFF_AMOUNT=0.00&amp;WP_ACTION=sale&amp;WSO_IPN_VERSION=1&amp;WP_TXNID=35&amp;WSO_SALE_ID=wp_sale_3&amp;payer_email=nn%2Bpaypal%40freelancer.com&amp;WP_SALE_CURRENCY=USD&amp;WSO_SALE_AMOUNT=43&amp;WSO_AFF_EMAIL=&amp;TRANSACTIONID=35&amp;WSO_CUSTOMER_NAME=Neil+calabroso
  </code></pre>
  
  <p>The expected output is a series of JSON key-value pairs:</p>
  
  <pre><code>{
      "WSO_SIGNATURE": "1d9ce78c2778ecf795a93009a09f8102dd4ef38a",
      "WP_BUYER_NAME": "Neil calabroso",
      "WP_ITEM_NAME": "Welcome to the Vault",
      "SHIPTONAME": "Neil calabroso",
      "WSO_PRODUCT_ID": "wp_product_3",
      "WP_AFFID": "",
      "WSO_SALE_CURRENCY": "USD",
      "EMAIL": "nn+paypal@freelancer.com",
      "WP_ITEM_NUMBER": "wp_product_3",
      "PAYMENTSTATUS": "COMPLETED",
      "WP_BUYER_EMAIL": "nn+paypal@freelancer.com",
      "WSO_PRODUCT_NAME": "Welcome to the Vault",
      "WP_SALEID": "wp_sale_3",
      "AMT": "43",
      "WSO_CUSTOMER_EMAIL": "nn+paypal@freelancer.com",
      "WSO_SALE_ACTION": "SALE",
      "WP_SALE_AMOUNT": "43",
      "WSO_TXN_ID": "35",
      "saleid": "wp_sale_3",
      "WSO_AFF_AMOUNT": "0.00",
      "WP_ACTION": "sale",
      "WSO_IPN_VERSION": "1",
      "WP_TXNID": "35",
      "WSO_SALE_ID": "wp_sale_3",
      "payer_email": "nn+paypal@freelancer.com",
      "WP_SALE_CURRENCY": "USD",
      "WSO_SALE_AMOUNT": "43",
      "WSO_AFF_EMAIL": "",
      "TRANSACTIONID": "35",
      "WSO_CUSTOMER_NAME": "Neil calabroso"
  }
  </code></pre>