tj / node-querystring

querystring parser for node and the browser - supporting nesting (used by Express, Connect, etc)
MIT License
455 stars 66 forks source link

Query String with Array of Objects doesn't seem to work correctly #30

Open jthereliable opened 12 years ago

jthereliable commented 12 years ago

I'm working with PayPal IPN notifications right now and I'm getting an issue with express.bodyParser

transaction%5B1%5D.status_for_sender_txn=Completed&transaction%5B1%5D.receiver=...

What I'm getting back is:

{
        'transaction': {
                '0].id_for_sender_tx': '5WF402232G129313C',
                '0].receive': '......'
        }
}

I'm not sure if what PayPal is sending back to me is correct protocol but how the data is being parsed really messes up what I have to send back to them.

tj commented 12 years ago

there isn't really anything "correct" but typically "transaction[1].foo=" is just transaction[1][foo]=", im sure we can fit in support for that though. do you mind posting the whole thing? or most of it for a test case

jthereliable commented 12 years ago

I had to strip the values out of some things, but here's what I got back:

transaction%5B0%5D.is_primary_receiver=true&transaction%5B0%5D.id_for_sender_txn=transaction_info&log_default_shipping_address_in_transaction=false&transaction%5B0%5D.receiver=receiver_email&action_type=PAY&ipn_notification_url=ipn_url&transaction%5B1%5D.paymentType=SERVICE&transaction%5B0%5D.amount=cost&charset=windows-1252&transaction_type=Adaptive+Payment+PAY&transaction%5B1%5D.id_for_sender_txn=transaction_detail&transaction%5B1%5D.is_primary_receiver=false&transaction%5B0%5D.status=Completed&notify_version=UNVERSIONED&transaction%5B0%5D.id=transaction_id&cancel_url=cancel_url&transaction%5B1%5D.status_for_sender_txn=Completed&transaction%5B1%5D.receiver=receiver_email&verify_sign=verify_sign&sender_email=buyer_email&fees_payer=PRIMARYRECEIVER&transaction%5B0%5D.status_for_sender_txn=Completed&return_url=return_url&transaction%5B0%5D.paymentType=SERVICE&memo=memo&transaction%5B1%5D.amount=cost&reverse_all_parallel_payments_on_error=false&tracking_id=tracking_id&transaction%5B1%5D.pending_reason=NONE&pay_key=pay_key&transaction%5B1%5D.id=transaction_id&transaction%5B0%5D.pending_reason=NONE&status=COMPLETED&transaction%5B1%5D.status=Completed&test_ipn=1&payment_request_date=Fri+Jan+06+10%3A02%3A31+PST+2012

With the query parser, I get:

{ transaction:
   { '0].is_primary_receive': 'true',
     '0].id_for_sender_tx': 'transaction_info',
     '0].receive': 'receiver_email',
     '1].paymentTyp': 'SERVICE',
     '0].amoun': 'cost',
     '1].id_for_sender_tx': 'transaction_detail',
     '1].is_primary_receive': 'false',
     '0].statu': 'Completed',
     '0].i': 'transaction_id',
     '1].status_for_sender_tx': 'Completed',
     '1].receive': 'receiver_email',
     '0].status_for_sender_tx': 'Completed',
     '0].paymentTyp': 'SERVICE',
     '1].amoun': 'cost',
     '1].pending_reaso': 'NONE',
     '1].i': 'transaction_id',
     '0].pending_reaso': 'NONE',
     '1].statu': 'Completed' },
  log_default_shipping_address_in_transaction: 'false',
  action_type: 'PAY',
  ipn_notification_url: 'ipn_url',
  charset: 'windows-1252',
  transaction_type: 'Adaptive Payment PAY',
  notify_version: 'UNVERSIONED',
  cancel_url: 'cancel_url',
  verify_sign: 'verify_sign',
  sender_email: 'buyer_email',
  fees_payer: 'PRIMARYRECEIVER',
  return_url: 'return_url',
  memo: 'memo',
  reverse_all_parallel_payments_on_error: 'false',
  tracking_id: 'tracking_id',
  pay_key: 'pay_key',
  status: 'COMPLETED',
  test_ipn: '1',
  payment_request_date: 'Fri Jan 06 10:02:31 PST 2012' }
tj commented 12 years ago

thanks that will do

atheken commented 11 years ago

@visionmedia It looks like the issue is that the [] balancing is off. I was able to get things parsed correctly by leaving off one of the closing brackets ( ']' ) on my fields, is this being worked on? or is this something that would be good for a fork/fix?

sunknudsen commented 10 years ago

@visionmedia I am running into the same issue. Did someone find a fix?